Creating an iCal Calendar Event Using PHP

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

I have no code to include, because I have no starting point. Any suggestions on where I should start?

+6
source share
3 answers

A few years ago, I started writing the iCalendar library. This is in a rather alpha stage (and I practically abandoned it), at that time there was no PHP 5, and there is not much functionality there, but:

  • I have a lot of code that goes into modeling the iCalendar RFC (you can look in it).
  • He has the ability to programmatically create events and spit out the iCal format.

Hope this helps:

+3
source

Start here. This will give you the file format for the icalendar event. then you can use php to output such a file with your user data:

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

I used this as a guide for projects in the past.

+2
source

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 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 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 
+2
source

Source: https://habr.com/ru/post/892999/


All Articles