PHP code example of spatie / calendar-links

1. Go to this page and download the library: Download spatie/calendar-links 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 / calendar-links example snippets


use Spatie\CalendarLinks\Link;

Link::create(
    'Birthday party',
    new DateTime('2027-03-15 10:00', new DateTimeZone('Europe/Brussels')),
    new DateTime('2027-03-15 17:00', new DateTimeZone('Europe/Brussels')),
)->google();


use Spatie\CalendarLinks\Link;

$from = new DateTime('2027-03-15 10:00', new DateTimeZone('Europe/Brussels'));
$to = new DateTime('2027-03-15 17:00', new DateTimeZone('Europe/Brussels'));

$link = Link::create('Birthday party', $from, $to)
    ->description('A full day of hands-on testing. Bring a laptop.')
    ->address('Samberstraat 69D, 2060 Antwerp, Belgium');

// A link that creates the event on Google calendar
echo $link->google();

// A link that creates the event on Yahoo calendar
echo $link->yahoo();

// A link that creates the event on outlook.live.com
echo $link->webOutlook();

// A link that creates the event on outlook.cloud.microsoft
echo $link->webOffice();

// A data URI holding an ics file, for iCal, Apple Calendar and Outlook
echo $link->ics();

// The raw ics body instead of a data URI, to attach to an email as a file
echo $link->ics([], ['format' => 'file']);

// Any generator of your own
echo $link->formatWith(new \Your\Generator());

$flight = Link::create(
    'NH 106 Tokyo to Los Angeles',
    new DateTime('2027-03-15 09:00', new DateTimeZone('Asia/Tokyo')),
    new DateTime('2027-03-15 09:30', new DateTimeZone('America/Los_Angeles')),
);

$link->guest('[email protected]')
    ->guests(['[email protected]', '[email protected]'])
    ->guest('[email protected]', optional: true);

echo $link->yahoo(['TYPE' => 7]);

echo $link->ics([
    'UID' => 'workshop-2027-03-15',
    'URL' => 'https://example.com/events/birthday-party',
    'RRULE' => 'FREQ=WEEKLY;BYDAY=MO,WE,FR',
    'TRANSP' => 'TRANSPARENT',
    'CLASS' => 'PRIVATE',
    'REMINDER' => ['DESCRIPTION' => 'The workshop starts in 15 minutes'],
]);

echo $link->ics([
    'UID' => 'workshop-2027-03-15',
    'DTSTAMP' => new DateTimeImmutable('now'),
]);

echo $link->ics([], ['format' => 'file']); // the raw ics body, rather than a data URI

use Spatie\CalendarLinks\Generators\Ics;
use Spatie\CalendarLinks\Link;

class MyIcs extends Ics
{
    /** @return list<string> */
    #[\Override]
    protected function additionalEventProperties(Link $link): array
    {
        return [
            'CATEGORIES:'.$this->escapeString('Workshops'),
            'STATUS:CONFIRMED',
        ];
    }
}

echo $link->formatWith(new MyIcs());

https://calendar.google.com/calendar/render?action=TEMPLATE&dates=20270315T090000/20270315T093000&stz=Asia/Tokyo&etz=America/Los_Angeles&text=NH+106+Tokyo+to+Los+Angeles