Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
one event example of iCalendar implementation in PHP
<?php
function escapeString($string) {
return preg_replace('/([\,;])/','\\\$1', $string);
}
function dateToCal($timestamp) {
return date('Ymd', $timestamp) .'T'. date('His', $timestamp) . "Z";
}
$eol = "\r\n";
$load = "BEGIN:VCALENDAR" . $eol .
"VERSION:2.0" . $eol .
"PRODID:-//project/author//NONSGML v1.0//EN" . $eol .
"CALSCALE:GREGORIAN" . $eol .
"BEGIN:VEVENT" . $eol .
"DTSTAMP:" . dateToCal(time()) . $eol .
"DTSTART:" . dateToCal($from_timestamp) . $eol .
"DTEND:" . dateToCal($till_timestamp) . $eol .
"UID:" . $uid . $eol .
"DESCRIPTION:" . htmlspecialchars($description) . $eol .
"URL;VALUE=URI:" . htmlspecialchars($shortUrl) . $eol .
"SUMMARY:" . htmlspecialchars($title) . $eol .
"END:VEVENT" . $eol .
"END:VCALENDAR";
$filename="Event-".$title_no_space . ".ics";
// Set the headers
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $filename);
// Dump load
echo $load;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.