除了Stefan Gehrig的答案和Dave None的答案(以及mmmshuddup的答案)以外,还请注意个人经历:
在http://severinghaus.org/projects/icv/上使用ICS验证程序时,我同时使用\ n和PHP_EOL遇到验证问题。
我了解到必须使用\ r \ n才能对其进行正确验证,所以这是我的解决方案:
function dateToCal($timestamp) {
return date('Ymd\Tgis\Z', $timestamp);
}
function escapeString($string) {
return preg_replace('/([\,;])/','\\\$1', $string);
}
$eol = "\r\n";
$load = "BEGIN:VCALENDAR" . $eol .
"VERSION:2.0" . $eol .
"PRODID:-//project/author//NONSGML v1.0//EN" . $eol .
"CALSCALE:GREGORIAN" . $eol .
"BEGIN:VEVENT" . $eol .
"DTEND:" . dateToCal($end) . $eol .
"UID:" . $id . $eol .
"DTSTAMP:" . dateToCal(time()) . $eol .
"DESCRIPTION:" . htmlspecialchars($title) . $eol .
"URL;VALUE=URI:" . htmlspecialchars($url) . $eol .
"SUMMARY:" . htmlspecialchars($description) . $eol .
"DTSTART:" . dateToCal($start) . $eol .
"END:VEVENT" . $eol .
"END:VCALENDAR";
$filename="Event-".$id;
// Set the headers
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $filename);
// Dump load
echo $load;
这停止了我的解析错误,并使我的ICS文件正确验证。