Error message when running .ics script?

时间:2015-09-14 15:48:29

标签: php mysql icalendar

When I run the following code and open in ical I get this message "Calendar can’t read this calendar file. No events have been added to your calendar." Any idea where I have gone wrong?

require_once('calendar.php');
$start = date('Ymd', $row['CourseStartDate']) . 'T' .date('His', $row['CourseStartDate']) . 'z';
$end = date('Ymd', $row['CourseEndDate']) . 'T' .date('His', $row['CourseEndDate']) . 'z';
header("content-type:text/calendar;charset=utf-8");
header("content-disposition:inline;filename=bookings.ics");
    echo "BEGIN:VCALENDAR\n";
    echo "VERSION:2.0\n";
    echo "METHOD:REQUEST\n";
while($row = mysql_fetch_assoc($result)){
    echo "BEGIN:VEVENT\n";
    echo "UID:".date('Ymd') . 'T' .date('His').rand()."firstaid4life.com";
    echo "DTSTAMP:".date('Ymd').'T'.date('His')."/n";
    echo "DTSTART:{$start}\n";
    echo "DTEND:{$end}\n";
    echo "SUMMARY:{$row['CourseTitle']}\n";
    echo "ATTENDEES:{$row['Attendees']}\n";
    echo "END:VEVENT\n";
}
    echo "END: VCALENDAR\n";

Thanks.

1 个答案:

答案 0 :(得分:1)

根据ics specification,行应该由CRLF序列分隔,因此您应该使用\r\n进行换行。

还要注意该行

echo "UID:".date('Ymd') . 'T' .date('His').rand()."firstaid4life.com";
echo "DTSTAMP:".date('Ymd').'T'.date('His')."/n";

完全错过了一个换行符。 /n 换行符,\n是正确的。您的代码至少应该是(可能用\n s替换所有\r\n

echo "UID:".date('Ymd') . 'T' .date('His').rand()."firstaid4life.com\n";
echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n";