Official PHP library for Holiday API providing quick and easy access to holiday information from applications written in PHP.
Please note, version 2.x of this library is a full rewrite of the 1.x series. The interfacing to the library has been simplified and existing applications upgrading to 2.x will need to be updated.
Version 1.x Syntax (Old) | Version 2.x Syntax (New) |
---|---|
$holiday_api = new \HolidayAPI\v1($key); |
$holiday_api = new \HolidayAPI\Client(['key' => $key]); |
Version 1.x of the library can still be found here.
Full documentation of the Holiday API endpoints is available here.
composer require holidayapi/holidayapi-php
<?php
$key = 'Insert your API key here';
$holiday_api = new \HolidayAPI\Client(['key' => $key]);
try {
// Fetch supported countries and subdivisions
$countries = $holiday_api->countries();
// Fetch supported languages
$languages = $holiday_api->languages();
// Fetch holidays with minimum parameters
$holidays = $holiday_api->holidays([
'country' => 'US',
'year' => 2019,
]);
var_dump($countries, $languages, $holidays);
} catch (Exception $e) {
var_dump($e);
}
<?php
$holiday_api->countries();
<?php
$holiday_api->countries([
'public' => true,
]);
<?php
$holiday_api->countries([
'country' => 'NO',
]);
<?php
$holiday_api->countries([
'search' => 'united',
]);
<?php
$holiday_api->languages();
<?php
$holiday_api->languages([
'language' => 'es',
]);
<?php
$holiday_api->languages([
'search' => 'Chinese',
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
'month' => 7,
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
'month' => 7,
'day' => 4,
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
'month' => 7,
'day' => 4,
'upcoming' => true,
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
'month' => 7,
'day' => 4,
'previous' => true,
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
'public' => true,
]);
<?php
$holiday_api->holidays([
'country' => 'GB-ENG',
'year' => 2019,
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
'subdivisions' => true,
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
'search' => 'New Year',
]);
<?php
$holiday_api->holidays([
'country' => 'US',
'year' => 2019,
'language' => 'zh', // Chinese (Simplified)
]);
<?php
$holiday_api->holidays([
'country' => 'US,GB,NZ',
'year' => 2019,
]);
$holiday_api->holidays([
'country' => ['US', 'GB', 'NZ'],
'year' => 2019,
]);
<?php
$holiday_api->workday([
'country' => 'US',
'start' => '2019-07-01',
'days' => 7,
]);