Created
April 16, 2020 12:49
-
-
Save benbyford/ada3a229501c769880b0aa2b13276d3e to your computer and use it in GitHub Desktop.
one event example of iCalendar implementation in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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