3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Variables used in this script: // $summary - text title of the event // $datestart - the starting date (in seconds since unix epoch) // $dateend - the ending date (in seconds since unix epoch) // $address - the event's address // $uri - the URL of the event (add http://) // $description - text description of the event // $filename - the name of this file for saving (e.g. my-event-name.ics) // // Notes: // - the UID should be unique to the event, so in this case I'm just using // uniqid to create a uid, but you could do whatever you'd like. // // - iCal requires a date format of "yyyymmddThhiissZ". The "T" and "Z" // characters are not placeholders, just plain ol' characters. The "T" // character acts as a delimeter between the date (yyyymmdd) and the time // (hhiiss), and the "Z" states that the date is in UTC time. Note that if // you don't want to use UTC time, you must prepend your date-time values // with a TZID property. See RFC 5545 section 3.3.5 // // - The Content-Disposition: attachment; header tells the browser to save/open // the file. The filename param sets the name of the file, so you could set // it as "my-event-name.ics" or something similar. // // - Read up on RFC 5545, the iCalendar specification. There is a lot of helpful // info in there, such as formatting rules. There are also many more options // to set, including alarms, invitees, busy status, etc. // // https://www.ietf.org/rfc/rfc5545.txt // 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
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dt56V
function name:  (null)
number of ops:  50
compiled vars:  !0 = $filename, !1 = $dateend, !2 = $address, !3 = $description, !4 = $uri, !5 = $summary, !6 = $datestart
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-type%3A+text%2Fcalendar%3B+charset%3Dutf-8'
          2        DO_ICALL                                                 
   34     3        INIT_FCALL                                               'header'
          4        CONCAT                                           ~8      'Content-Disposition%3A+attachment%3B+filename%3D', !0
          5        SEND_VAL                                                 ~8
          6        DO_ICALL                                                 
   56     7        ECHO                                                     'BEGIN%3AVCALENDAR%0AVERSION%3A2.0%0APRODID%3A-%2F%2Fhacksw%2Fhandcal%2F%2FNONSGML+v1.0%2F%2FEN%0ACALSCALE%3AGREGORIAN%0ABEGIN%3AVEVENT%0ADTEND%3A'
   61     8        INIT_FCALL                                               'datetocal'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $10     
         11        ECHO                                                     $10
   62    12        ECHO                                                     'UID%3A'
         13        INIT_FCALL                                               'uniqid'
         14        DO_ICALL                                         $11     
         15        ECHO                                                     $11
   63    16        ECHO                                                     'DTSTAMP%3A'
         17        INIT_FCALL                                               'datetocal'
         18        INIT_FCALL                                               'time'
         19        DO_ICALL                                         $12     
         20        SEND_VAR                                                 $12
         21        DO_FCALL                                      0  $13     
         22        ECHO                                                     $13
   64    23        ECHO                                                     'LOCATION%3A'
         24        INIT_FCALL                                               'escapestring'
         25        SEND_VAR                                                 !2
         26        DO_FCALL                                      0  $14     
         27        ECHO                                                     $14
   65    28        ECHO                                                     'DESCRIPTION%3A'
         29        INIT_FCALL                                               'escapestring'
         30        SEND_VAR                                                 !3
         31        DO_FCALL                                      0  $15     
         32        ECHO                                                     $15
   66    33        ECHO                                                     'URL%3BVALUE%3DURI%3A'
         34        INIT_FCALL                                               'escapestring'
         35        SEND_VAR                                                 !4
         36        DO_FCALL                                      0  $16     
         37        ECHO                                                     $16
   67    38        ECHO                                                     'SUMMARY%3A'
         39        INIT_FCALL                                               'escapestring'
         40        SEND_VAR                                                 !5
         41        DO_FCALL                                      0  $17     
         42        ECHO                                                     $17
   68    43        ECHO                                                     'DTSTART%3A'
         44        INIT_FCALL                                               'datetocal'
         45        SEND_VAR                                                 !6
         46        DO_FCALL                                      0  $18     
         47        ECHO                                                     $18
   69    48        ECHO                                                     'END%3AVEVENT%0AEND%3AVCALENDAR'
   70    49      > RETURN                                                   1

Function datetocal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dt56V
function name:  dateToCal
number of ops:  7
compiled vars:  !0 = $timestamp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   46     1        INIT_FCALL                                               'date'
          2        SEND_VAL                                                 'Ymd%5CTHis%5CZ'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   47     6*     > RETURN                                                   null

End of function datetocal

Function escapestring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dt56V
function name:  escapeString
number of ops:  8
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   51     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%28%5B%5C%2C%3B%5D%29%2F'
          3        SEND_VAL                                                 '%5C%5C%241'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
   52     7*     > RETURN                                                   null

End of function escapestring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.92 ms | 1403 KiB | 30 Q