PHP code example of spatie / icalendar-generator
1. Go to this page and download the library: Download spatie/icalendar-generator library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / icalendar-generator example snippets
use Spatie\IcalendarGenerator\Components\Calendar;
use Spatie\IcalendarGenerator\Components\Event;
Calendar::create('Laracon online')
->event(Event::create('Creating calender feeds')
->startsAt(new DateTime('6 March 2019 15:00'))
->endsAt(new DateTime('6 March 2019 16:00'))
)
->get();
Event::create()
->attachment('https://spatie.be/logo.svg')
->attachment('https://spatie.be/feed.xml', 'application/json')
...
Event::create()
->embeddedAttachment($file->toString())
->embeddedAttachment($fileString, 'application/json')
->embeddedAttachment($base64String, 'application/json', needsEncoding: false)
...
$timezoneEntry = TimezoneEntry::create(
TimezoneEntryType::daylight(),
new DateTime('23 march 2020'),
'+00:00',
'+02:00'
);
$timezone = Timezone::create('Europe/Brussels')
->entry($timezoneEntry)
...
Calendar::create()
->timezone($timezone)
...
Event::create('Laracon Online')
->repeatOn(new DateTime('05/16/2020 12:00:00'));
Event::create('Laracon Online')
->repeatOn([new DateTime('05/16/2020 12:00:00'), new DateTime('08/13/2020 15:00:00')]);
$rrule = RRule::frequency(RecurrenceFrequency::daily());
$rrule = RRule::frequency(RecurrenceFrequency::daily())->starting(new DateTime('now'));
$rrule = RRule::frequency(RecurrenceFrequency::daily())->until(new DateTime('now'));
$rrule = RRule::frequency(RecurrenceFrequency::daily())->times(10);
$rrule = RRule::frequency(RecurrenceFrequency::daily())->interval(2);
$rrule = RRule::frequency(RecurrenceFrequency::monthly())->onWeekDay(
RecurrenceDay::friday()
);
$rrule = RRule::frequency(RecurrenceFrequency::monthly())->onWeekDay(
RecurrenceDay::friday(), 3
);
$rrule = RRule::frequency(RecurrenceFrequency::monthly())->onWeekDay(
RecurrenceDay::sunday(), -1
);
$rrule = RRule::frequency(RecurrenceFrequency::monthly())->onMonthDay(16);
$rrule = RRule::frequency(RecurrenceFrequency::monthly())->onMonthDay(
[5, 10, 15, 20]
);
$rrule = RRule::frequency(RecurrenceFrequency::monthly())->onMonth(
[RecurrenceMonth::april(), RecurrenceMonth::may(), RecurrenceMonth::june()]
);
$rrule = RRule::frequency(RecurrenceFrequency::monthly())->onMonth(
RecurrenceMonth::october()
);
$rrule = RRule::frequency(RecurrenceFrequency::monthly())->weekStartsOn(
ReccurenceDay::monday()
);
Event::create('Laracon Online')
->rrule(RRule::frequency(RecurrenceFrequency::daily()))
->doNotRepeatOn(new DateTime('05/16/2020 12:00:00'));
Event::create('Laracon Online')
->rrule(RRule::frequency(RecurrenceFrequency::daily()))
->doNotRepeatOn([new DateTime('05/16/2020 12:00:00'), new DateTime('08/13/2020 15:00:00')]);
Event::create('SymfonyCon')
->rruleAsString('FREQ=DAILY;INTERVAL=1');
Event::create('SymfonyCon')
->rruleAsString(
'DTSTART=20231207T090000Z;FREQ=DAILY;INTERVAL=1;UNTIL=20231208T090000Z',
new DateTime('7 december 2023 09:00:00', new DateTimeZone('UTC')),
new DateTime('8 december 2023 09:00:00', new DateTimeZone('UTC'))
);
$timezone = Timezone::create('Europe/Brussels');
$timezone = Timezone::create('Europe/Brussels')
->lastModified(new DateTime('16 may 2020 12:00:00'));
$timezone = Timezone::create('Europe/Brussels')
->url('https://spatie.be');
$entry = TimezoneEntry::create(
TimezoneEntryType::standard(),
new DateTime('16 may 2020 12:00:00'),
'+00:00',
'+02:00'
);
$entry = TimezoneEntry::create(...)
->name('Europe - Brussels')
->description('Belgian timezones ftw!');
$entry = TimezoneEntry::create(...)
->rrule(RRule::frequency(RecurrenceFrequency::daily()));
$timezone = Timezone::create('Europe/Brussels')
->entry($timezoneEntry);
$timezone = Timezone::create('Europe/Brussels')
->entry([$timezoneEntryOne, $timezoneEntryTwo]);
$calendar = Calendar::create('Calendar with timezones')
->timezone($timezone);
$calendar = Calendar::create('Calendar with timezones')
->timezone([$timezoneOne, $timezoneTwo]);
Calendar::create()
->appendProperty(
TextProperty::create('ORGANIZER', '[email protected] ')
)
...
$property = TextProperty::create('ORGANIZER', '[email protected] ')
->addParameter(Parameter::create('CN', 'RUBEN VAN ASSCHE'));
Calendar::create()
->appendProperty($property)
...
Calendar::create()
->appendSubComponent(
Event::create('Extending icalendar-generator')
)
...
php
$calendar = Calendar::create();
php
$calendar = Calendar::create('Laracon Online');
php
Calendar::create('Laracon Online')->get(); // BEGIN:VCALENDAR ...
php
Calendar::create('Laracon Online')
->refreshInterval(5)
...
php
Event::create()
->address('Kruikstraat 22, 2018 Antwerp, Belgium')
->addressName('Spatie HQ')
->coordinates(51.2343, 4.4287)
...
php
Event::create()
->organizer('[email protected] ', 'Ruben')
...
php
Event::create()
->attendee('[email protected] ', 'Ruben', ParticipationStatus::needs_action(),
php
Event::create()
->transparent()
...
php
Event::create()
->fullDay()
...
php
Event::create()
->status(EventStatus::cancelled())
...
php
new DateTime('6 march 2019 15:00', new DateTimeZone('Europe/Brussels'))
php
Calendar::create()
->withoutTimezone()
...
php
Calendar::create()
->withoutAutoTimezoneComponents()
...
php
Event::create('Laracon Online')
->rrule(RRule::frequency(RecurrenceFrequency::monthly()));
php
$calendar = Calendar::create('Laracon Online');
return response($calendar->get())
->header('Content-Type', 'text/calendar; charset=utf-8');
php
$calendar = Calendar::create('Laracon Online');
return response($calendar->get(), 200, [
'Content-Type' => 'text/calendar; charset=utf-8',
'Content-Disposition' => 'attachment; filename="my-awesome-calendar.ics"',
]);