问题描述
任何Google搜索PHP ical只是带来了phpicalendar和如何解析或读取INical文件。我只是想写一个PHP文件,从我的数据库拉出事件,并以ical格式写出来。
Any Google search on PHP ical just brings up phpicalendar and how to parse or read IN ical files. I just want to write a PHP file that pulls events from my database and writes them out in ical format.
我的问题是我找不到任何地方,将回答两
My problem is I can't find anywhere that will answer two questions:
- 确切的格式是什么,包括标题,文件格式,页脚等?
- 如果我使用.php扩展名来构建这个文件,那么这个文件必须具有什么内容,才能被Google日历等正确读取。如何将其发布为ical?我必须写一个新的.ics文件吗?或者,Google日历等会读取一个.php文件作为ical只要内容是正确的格式? (很像一个style.css.php文件将被读为CSS文件,如果内容实际上是CSS等)
推荐答案
如果使用Google日历,这应该非常简单不需要 *。ics
-extension(这将需要在服务器中重写一些URL)。
This should be very simple if Google Calendar does not require the *.ics
-extension (which will require some URL rewriting in the server).
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR";
//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
echo $ical;
exit;
这本质上就是让客户端认为您正在提供iCalendar文件可能会有一些关于缓存,文本编码等问题。但你可以开始尝试这个简单的代码。
That's essentially all you need to make a client think that you're serving a iCalendar file, even though there might be some issues regarding caching, text encoding and so on. But you can start experimenting with this simple code.
这篇关于如何使用PHP动态发布ical文件以供Google日历读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!