iCal Library for PHP

News

January 21st, 2020

php-ical.png

Markus Poerschke has PHP package that provides an abstraction layer for creating iCalendars:

1use Eluceo\iCal\Component\Calendar;
2use Eluceo\iCal\Component\Event;
3 
4$vCalendar = new Calendar('www.example.com');
5$vCalendar->setName('Example Calendar');
6$vCalendar->setTimezone('America/New_York');
7 
8$vEvent = new Event();
9$vEvent
10 ->setDtStart(new \DateTime('2012-12-24'))
11 ->setDtEnd(new \DateTime('2012-12-24'))
12 ->setNoTime(true)
13 ->setSummary('Christmas');
14 
15$vCalendar->addComponent($vEvent);
16 
17header('Content-Type: text/calendar; charset=utf-8');
18header('Content-Disposition: attachment; filename="cal.ics"');
19 
20echo $vCalendar->render();

The library supports the following iCalendar components:

  • VCALENDAR
  • VEVENT
  • VALARM
  • VTIMEZONE

After incorporating it in your application, here’s an example of linking to a calendar:

1<a href="webcal://www.example.com/holidays.ics">Subscribe (iCal)</a>

You can learn more about this package, get full installation instructions, and view the source code on GitHub at markuspoerschke/iCal.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.