除了Stefan Gehrig的回答和Dave None的答案(以及mmmshuddup的回复)之外,还有个人经验的说明:
当我在 \n 和 PHP_EOL 使用 ICS 验证程序时,我遇到了验证问题 http://severinghaus.org/projects/icv/
我了解到我必须使用 \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文件正确验证。