PHP中的订阅日历URL [英] Subscription Calendar URL in PHP
本文介绍了PHP中的订阅日历URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一个基于事件管理的项目中,每个用户在那里存储事件详细信息以及开始和结束日期。现在,我想要一种功能来订阅桌面应用程序(Outlook,苹果和Google日历的Ical),以便任何新事件保存在数据库中,它会自动同步到桌面应用程序。实现此功能的最佳方法是什么?
推荐答案
以下是用于生成单个事件iCal输出的示例代码:
Here's sample code for generating a single event iCal output:
$eventData = array(
'title' => $event->getTitle(),
'address' => $address,
'description' => strip_tags($event->getBody()),
'stage' => $stage,
'date' => $event->getDate()
);
// Build the ics file
$ical= 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTEND:' . $this->dateToCal($eventData['date']) . '
UID:' . md5($eventData['title']) . '
DTSTAMP:' . time() . '
LOCATION:' . $eventData['address'] . '
DESCRIPTION:' . $eventData['description'] . '
URL;VALUE=URI:http://go.okdo.it' . '
SUMMARY:' . $eventData['title'] . '
DTSTART:' . $this->dateToCal($eventData['date']) . '
END:VEVENT
END:VCALENDAR';
以下是将日期对象格式化为iCal格式的函数:
Here's the function that formats date objects to iCal format:
function dateToCal($timestamp)
{
return date('Ymd\This', time()) . 'Z';
}
在输出内容之前,您需要设置适当的标题:
Before outputting the content, you need to set appropriate headers:
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $task->getTitle());
echo $ical;
这篇关于PHP中的订阅日历URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文