如何导出ics文件中的数据?
How to export data in a ics file?
我找到了针对单个事件的解决方案:How to generate .ics file using PHP for a given date range and time 但我需要在单个文件中导出多个事件。
我不太确定在给定的 class 中我应该更新什么,你能告诉我一些应该改变的方向吗?
我真的很讨厌您提供的 link 中非常旧的 PHP 代码,但试试这个更新:
<?php
class ICS {
var $data = "";
var $name;
var $start = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:PUBLISH\n";
var $end = "END:VCALENDAR\n";
function ICS($name) {
$this->name = $name;
}
function add($start,$end,$name,$description,$location) {
$this->data .= "BEGIN:VEVENT\nDTSTART:".date("Ymd\THis\Z",strtotime($start))."\nDTEND:".date("Ymd\THis\Z",strtotime($end))."\nLOCATION:".$location."\nTRANSP: OPAQUE\nSEQUENCE:0\nUID:\nDTSTAMP:".date("Ymd\THis\Z")."\nSUMMARY:".$name."\nDESCRIPTION:".$description."\nPRIORITY:1\nCLASS:PUBLIC\nBEGIN:VALARM\nTRIGGER:-PT10080M\nACTION:DISPLAY\nDESCRIPTION:Reminder\nEND:VALARM\nEND:VEVENT\n";
}
function save() {
file_put_contents($this->name.".ics",$this->getData());
}
function show() {
header("Content-type:text/calendar");
header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');
Header('Content-Length: '.strlen($this->getData()));
Header('Connection: close');
echo $this->getData();
}
function getData() {
return $this->start . $this->data . $this->end;
}
}
?>
然后像这样使用它:
<?php
$event = new ICS("Test");
$event->add("2009-11-06 09:00","2009-11-06 21:00","Test Event1","This is an event 1","GU1 1AA");
$event->add("2010-11-06 09:00","2010-11-06 21:00","Test Event2","This is an event 2","GU1 1AA");
$event->save(); // $event->show();
?>
我找到了针对单个事件的解决方案:How to generate .ics file using PHP for a given date range and time 但我需要在单个文件中导出多个事件。
我不太确定在给定的 class 中我应该更新什么,你能告诉我一些应该改变的方向吗?
我真的很讨厌您提供的 link 中非常旧的 PHP 代码,但试试这个更新:
<?php
class ICS {
var $data = "";
var $name;
var $start = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:PUBLISH\n";
var $end = "END:VCALENDAR\n";
function ICS($name) {
$this->name = $name;
}
function add($start,$end,$name,$description,$location) {
$this->data .= "BEGIN:VEVENT\nDTSTART:".date("Ymd\THis\Z",strtotime($start))."\nDTEND:".date("Ymd\THis\Z",strtotime($end))."\nLOCATION:".$location."\nTRANSP: OPAQUE\nSEQUENCE:0\nUID:\nDTSTAMP:".date("Ymd\THis\Z")."\nSUMMARY:".$name."\nDESCRIPTION:".$description."\nPRIORITY:1\nCLASS:PUBLIC\nBEGIN:VALARM\nTRIGGER:-PT10080M\nACTION:DISPLAY\nDESCRIPTION:Reminder\nEND:VALARM\nEND:VEVENT\n";
}
function save() {
file_put_contents($this->name.".ics",$this->getData());
}
function show() {
header("Content-type:text/calendar");
header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');
Header('Content-Length: '.strlen($this->getData()));
Header('Connection: close');
echo $this->getData();
}
function getData() {
return $this->start . $this->data . $this->end;
}
}
?>
然后像这样使用它:
<?php
$event = new ICS("Test");
$event->add("2009-11-06 09:00","2009-11-06 21:00","Test Event1","This is an event 1","GU1 1AA");
$event->add("2010-11-06 09:00","2010-11-06 21:00","Test Event2","This is an event 2","GU1 1AA");
$event->save(); // $event->show();
?>