如何在给定的日期范围和时间下使用PHP生成.ics文件 [英] How to generate .ics file using PHP for a given date range and time

查看:134
本文介绍了如何在给定的日期范围和时间下使用PHP生成.ics文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种有效方法,根据给定的日期范围(开始日期-结束日期)和提醒时间,使用PHP生成可下载的".ics"文件.

I am trying to find an effective method to generate a downloadable ".ics" file using PHP, based on a given date range (start date - end date) and reminder time.

任何人都可以提供示例PHP代码来创建此功能.

Could any one provide me a sample PHP code to create this feature.

推荐答案

注意:原始博客文章不见了;通过arhcive.org链接保存.

Note: original blog post is gone; preserving with arhcive.org link.

复制并粘贴以上链接的信息:

Copy and paste the information of the above link:

<?php
class ICS {
    var $data;
    var $name;
    function ICS($start,$end,$name,$description,$location) {
        $this->name = $name;
        $this->data = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:PUBLISH\nBEGIN: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\nEND:VCALENDAR\n";
    }
    function save() {
        file_put_contents($this->name.".ics",$this->data);
    }
    function show() {
        header("Content-type:text/calendar");
        header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');
        Header('Content-Length: '.strlen($this->data));
        Header('Connection: close');
        echo $this->data;
    }
}
?>

将ICS文件输出到浏览器,并为用户提供打开或保存的选项

Output the ICS file to the browser and give the user the option to open or save

<?php
$event = new ICS("2009-11-06 09:00","2009-11-06 21:00","Test Event","This is an event made by Jamie Bicknell","GU1 1AA");
$event->show();
?>

将ICS文件保存到当前工作目录中的服务器上

Save the ICS file onto the server in the current working directory

<?php
$event = new ICS("2009-11-06 09:00","2009-11-06 21:00","Test Event","This is an event made by Jamie Bicknell","GU1 1AA");
$event->save();
?>

这篇关于如何在给定的日期范围和时间下使用PHP生成.ics文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆