1. Go to this page and download the library: Download benhall14/php-calendar 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/ */
benhall14 / php-calendar example snippets
$calendar = new Calendar;
$calendar->stylesheet();
(new Calendar)->display();
# create the calendar object
$calendar = new Calendar;
# change the weekly start date to "Monday"
$calendar->useMondayStartingDate();
# or revert to the default "Sunday"
$calendar->useSundayStartingDate();
# (optional) - if you want to use full day names instead of initials (ie, Sunday instead of S), apply the following:
$calendar->useFullDayNames();
# to revert to initials, use:
$calendar->useInitialDayNames();
# add your own table class(es)
$calendar->addTableClasses('class-1 class-2 class-3');
# or using an array of classes.
$calendar->addTableClasses(['class-1', 'class-2', 'class-3']);
# (optional) - if you want to hide certain weekdays from the calendar, for example a calendar without weekends, you can use the following methods:
$calendar->hideSaturdays() # This will hide Saturdays
$calendar->hideSundays(); # This will hide Sundays
$calendar->hideMondays(); # This will hide Mondays
$calendar->hideTuesdays(); # This will hide Tuesdays
$calendar->hideWednesdays(); # This will hide Wednesdays
$calendar->hideThursdays(); # This will hide Thursdays
$calendar->hideFridays(); # This will hide Fridays
# (optional) - Translated Calendars - currently, there is only Spanish, but see "Translations" below for adding your own strings.
$calendar->useSpanish();
# if needed, add event
$calendar->addEvent(
'2022-01-14', # start date in either Y-m-d or Y-m-d H:i if you want to add a time.
'2022-01-14', # end date in either Y-m-d or Y-m-d H:i if you want to add a time.
'My Birthday', # event name text
true, # should the date be masked - boolean default true
['myclass', 'abc'] # (optional) additional classes in either string or array format to be endar->draw(date('Y-m-d'), 'green'); # print a green calendar
echo $calendar->draw(date('Y-m-d'), 'grey'); # print a grey calendar
echo $calendar->draw(date('Y-m-d'), 'blue'); # print a blue calendar
# you can also call ->display(), which handles the echo'ing and adding the stylesheet.
echo $calendar->display(date('Y-m-d')); # draw this months calendar
$calendar->setTimeFormat('00:00', '00:00', 10)->useWeekView()->display(date('Y-m-d'), 'green');
# This will print a week view calendar with 10 minute slots from midnight to midnight - ie. 00:00, 00:10, 00:20 and so on.
$calendar = new Calendar;
$calendar->useMondayStartingDate();
$calendar->display(date('Y-m-d'), 'green');
# This will set up the days - simply copy/paste the code below and replace the Spanish initials and full-day names with your own. (NB - Leave the keys in English)
$calendar->setDays([
'sunday' => [
'initials' => 'D',
'full' => 'Domingo'
],
'monday' => [
'initials' => 'L',
'full' => 'Lunes',
],
'tuesday' => [
'initials' => 'M',
'full' => 'Martes',
],
'wednesday' => [
'initials' => 'X',
'full' => 'Miércoles',
],
'thursday' => [
'initials' => 'J',
'full' => 'Jueves',
],
'friday' => [
'initials' => 'V',
'full' => 'Viernes',
],
'saturday' => [
'initials' => 'S',
'full' => 'Sábado',
],
]);
# To add custom month names, simply copy/paste the code below and replace the Spanish month names with your own strings. (NB - Leave the keys in English)
$calendar->setMonths([
'january' => 'Enero',
'february' => 'Febrero',
'march' => 'Marzo',
'april' => 'Abril',
'may' => 'Mayo',
'june' => 'Junio',
'july' => 'Julio',
'august' => 'Agosto',
'september' => 'Septiembre',
'october' => 'Octubre',
'november' => 'Noviembre',
'december' => 'Diciembre'
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.