calendar / icsfile
This simple class generate a .ics file.
Requires
- php: >=8.2.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.85
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.1
- dev-master
- 9.2.2
- 9.2.1
- 9.2.0
- 9.1.0
- 9.0.0
- 8.0.0
- 7.1.0
- 7.0.0
- 6.3.2
- 6.3.1
- 6.3.0
- 6.2.0
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.4.2
- 5.4.1
- 5.4.0
- 5.3.0
- 5.2.0
- 5.1.4
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.0
- 4.0.1
- 4.0.0
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.0
- 2.3.0
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.1.1
- 1.1.0
This package is auto-updated.
Last update: 2025-08-10 15:16:00 UTC
README
This library allows you to easily generate iCalendar (.ics
) files in PHP, following the iCalendar (RFC 5545) specification.
Installation
Make sure you have installed the dependencies via Composer:
composer install
Include the Composer autoloader in your script:
require_once 'vendor/autoload.php';
Usage
Below is a basic example of creating an iCalendar event:
<?php
require_once 'vendor/autoload.php';
use Ical\Ical;
use Ical\IcalendarException;
try {
$ical = (new Ical())
->setName('test')
->setAddress('Paris')
->setDateStart(new \DateTimeImmutable('2014-11-21 15:00:00'))
->setDateEnd(new \DateTimeImmutable('2014-11-21 16:00:00'))
->setDateStamp(new \DateTimeImmutable('2014-11-21 15:00:00'))
->setCalendarType(CalendarTypeEnum::GREGORIAN)
->setTransparency(TransparencyEnum::OPAQUE) // Optional
->setDescription('wonder description')
->setSummary('Running')
->setOrganizer('foo@bar.fr') // Optional
->setFilename('myFileName')
->setStatus('CONFIRMED') // Optional
->setSequence(2); // Number of updates (default is 1, optional)
$ical->addHeader();
echo $ical->getICAL();
} catch (IcalendarException $exc) {
echo $exc->getMessage();
}
Methods
setName(string $name)
Sets the event name.
setAddress(string $address)
Sets the event location.
setDateStart(\DateTimeImmutable $date)
Sets the start date and time of the event.
setDateEnd(\DateTimeImmutable $date)
Sets the end date and time of the event.
setDateStamp(\DateTimeImmutable $date)
Sets the creation date/time of the event.
setCalendarType(CalendarTypeEnum $type)
Sets the calendar type (e.g., GREGORIAN
).
setTransparency(TransparencyEnum $transparency)
Sets whether the event is opaque or transparent for scheduling (optional).
setDescription(string $description)
Sets the event description.
setSummary(string $summary)
Sets the short summary/title of the event.
setOrganizer(string $email)
Sets the organizer’s email address (optional).
setFilename(string $filename)
Sets the filename for the generated .ics
file (without extension).
setStatus(string $status)
Sets the event status (CONFIRMED
, TENTATIVE
, etc.) (optional).
setSequence(int $sequence)
Sets the sequence number for event updates (default is 1
, optional).
addHeader()
Adds the required iCalendar headers.
getICAL(): string
Returns the generated iCalendar content.
Example Output
GIN:VCALENDAR
VERSION:2.0
PRODID:test
TRANSP:OPAQUE
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTART:20141121T150000Z
DTEND:20141121T160000Z
DTSTAMP:20141121T150000Z
SUMMARY:Running
UID:myUid
ORGANIZER:MAILTO:foo@bar.fr
LOCATION:Paris
DESCRIPTION:wonder description
SEQUENCE:2
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
Error Handling
All exceptions are instances of IcalendarException
.
Use try/catch
to handle errors when generating the calendar.