PHP code example of w3lifer / php-calendar

1. Go to this page and download the library: Download w3lifer/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/ */

    

w3lifer / php-calendar example snippets

 php
$phpCalendar = new PhpCalendar([
    'language' => 'en',
    'monthNames' => ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    'weekDayAbbrs' => ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'],
    'firstDayOfWeek' => 1,
    'timezone' => date_default_timezone_get(),
]);
 php
public function get(
    int $numberOfMonths = 12,
    int $startMonth = null, // Default: date('n')
    int $startYear = null // Default: date('Y')
): PhpCalendar
 php


$year = $_GET['year'] ?? null;
$phpCalendar = (new PhpCalendar())->get(12, 1, $year); // ->getYear($year);
$prevSearchParams = '?year=' . $phpCalendar->prevPeriodParams['startYear'];
$nextSearchParams = '?year=' . $phpCalendar->nextPeriodParams['startYear'];

 php


$numberOfMonths = $_GET['number-of-months'] ?? 6;
// Set `$startMonth` to `null` to get an auto-scrolling calendar
$startMonth = $_GET['start-month'] ?? 1;
$startYear = $_GET['start-year'] ?? null;
$phpCalendar = (new PhpCalendar())->get($numberOfMonths, $startMonth, $startYear);
$prevSearchParams =
    '?number-of-months=' . $numberOfMonths .
    '&start-month=' . $phpCalendar->prevPeriodParams['startMonth'] .
    '&start-year=' . $phpCalendar->prevPeriodParams['startYear'];
$nextSearchParams =
    '?number-of-months=' . $numberOfMonths .
    '&start-month=' . $phpCalendar->nextPeriodParams['startMonth'] .
    '&start-year=' . $phpCalendar->nextPeriodParams['startYear'];