使用 PHP 创建 iCal 日历事件

发布于 2024-11-25 06:33:33 字数 144 浏览 0 评论 0原文

我正在尝试创建一个 PHP 脚本来在 iCal 中创建日历事件。我在这里和 Google 中进行了搜索,只得到了有关将 iCal 事件导入 PHP 制作的日历的结果。这与我需要的相反。

我没有任何代码要包含,因为我没有起点。关于我应该从哪里开始有什么建议吗?

I am trying to create a PHP script that will create a calendar event in iCal. I have searched here and in Google and only come up with results that talk about importing iCal events to a PHP-made calendar. This is the opposite of what I need.

I don't have any code to include because I have no starting point. Any suggestions on where I should start?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初与友歌 2024-12-02 06:33:33

几年前,我开始编写一个 iCalendar 库。它正处于相当 alpha 阶段(我几乎已经放弃它),当时还没有 PHP 5,并且其中没有很多功能,但是:

  • 我确实有很多代码可以用于对 iCalendar RFC 进行建模(您可能想研究一下)
  • 它确实能够以编程方式创建事件并吐出 iCal 格式

希望它有所帮助:

A few years ago I had started writing an iCalendar library. It's in pretty alpha stage (and I 've practically given up on it), at the time there was no PHP 5, and there isn't a lot of functionality in there, but:

  • I do have a lot of code that goes into modeling the iCalendar RFC (you might want to look into it)
  • It does have the capability to programmatically create events and spit out iCal format

Hope it helps:

怎言笑 2024-12-02 06:33:33

从这里开始。这将为您提供 calendar 事件的文件格式。那么你可以使用 php 输出一个带有自定义数据的文件:

http://en.wikipedia.org /wiki/ICalendar

我过去曾用它作为项目的参考点。

Start Here. This will give you the file format for an icalendar event. then you can use php to output a file like this with your custom data:

http://en.wikipedia.org/wiki/ICalendar

I've used this as a reference point for projects in the past.

栀子花开つ 2024-12-02 06:33:33

试试这个(来自 https://gist.github.com/jakebellacera/635416

<?
// 1. Set the correct headers for this file
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $filename);

// 2. Define helper functions

// Converts a unix timestamp to an ics-friendly format
// NOTE: "Z" means that this timestamp is a UTC timestamp. If you need
// to set a locale, remove the "\Z" and modify DTEND, DTSTAMP and DTSTART
// with TZID properties (see RFC 5545 section 3.3.5 for info)
//
// Also note that we are using "H" instead of "g" because iCalendar's Time format
// requires 24-hour time (see RFC 5545 section 3.3.12 for info).
function dateToCal($timestamp) {
  return date('Ymd\THis\Z', $timestamp);
}

// Escapes a string of characters
function escapeString($string) {
  return preg_replace('/([\,;])/','\\\$1', $string);
}

// 3. Echo out the ics file's contents
?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTEND:<?= dateToCal($dateend) ?>
UID:<?= uniqid() ?>
DTSTAMP:<?= dateToCal(time()) ?>
LOCATION:<?= escapeString($address) ?>
DESCRIPTION:<?= escapeString($description) ?>
URL;VALUE=URI:<?= escapeString($uri) ?>
SUMMARY:<?= escapeString($summary) ?>
DTSTART:<?= dateToCal($datestart) ?>
END:VEVENT
END:VCALENDAR

Try this (from https://gist.github.com/jakebellacera/635416)

<?
// 1. Set the correct headers for this file
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $filename);

// 2. Define helper functions

// Converts a unix timestamp to an ics-friendly format
// NOTE: "Z" means that this timestamp is a UTC timestamp. If you need
// to set a locale, remove the "\Z" and modify DTEND, DTSTAMP and DTSTART
// with TZID properties (see RFC 5545 section 3.3.5 for info)
//
// Also note that we are using "H" instead of "g" because iCalendar's Time format
// requires 24-hour time (see RFC 5545 section 3.3.12 for info).
function dateToCal($timestamp) {
  return date('Ymd\THis\Z', $timestamp);
}

// Escapes a string of characters
function escapeString($string) {
  return preg_replace('/([\,;])/','\\\$1', $string);
}

// 3. Echo out the ics file's contents
?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTEND:<?= dateToCal($dateend) ?>
UID:<?= uniqid() ?>
DTSTAMP:<?= dateToCal(time()) ?>
LOCATION:<?= escapeString($address) ?>
DESCRIPTION:<?= escapeString($description) ?>
URL;VALUE=URI:<?= escapeString($uri) ?>
SUMMARY:<?= escapeString($summary) ?>
DTSTART:<?= dateToCal($datestart) ?>
END:VEVENT
END:VCALENDAR
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文