PHPackages                             w3lifer/php-calendar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. w3lifer/php-calendar

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

w3lifer/php-calendar
====================

PHP Calendar

1.0.4(1y ago)0110MITHTMLPHP ^8.0

Since Jan 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/w3roman/php-calendar)[ Packagist](https://packagist.org/packages/w3lifer/php-calendar)[ RSS](/packages/w3lifer-php-calendar/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

[php-calendar](https://packagist.org/packages/w3lifer/php-calendar)
===================================================================

[](#php-calendar)

- [Installation](#installation)
- [Usage](#usage)
    - [Default configuration](#default-configuration)
    - [Method `get()`](#method-get)
    - [Example of HTML calendar](#example-of-html-calendar)
    - [Example of 12-month calendar](#example-of-12-month-calendar)
    - [Example of periodic calendar](#example-of-periodic-calendar)
- [Tests](#tests)

Installation
------------

[](#installation)

```
composer require w3lifer/php-calendar
```

Usage
-----

[](#usage)

### Default configuration

[](#default-configuration)

> Can be changed as you wish

```
$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(),
]);
```

### Method `get()`

[](#method-get)

This method is the main public method in this class:

```
public function get(
    int $numberOfMonths = 12,
    int $startMonth = null, // Default: date('n')
    int $startYear = null // Default: date('Y')
): PhpCalendar
```

It returns a `PhpCalendar` object with the following public properties:

- `$html string` — calendar in HTML format
- `$prevPeriodParams array` — parameters for the previous period
- `$nextPeriodParams array` — parameters for the next period

The following period parameters are available (array keys):

- `numberOfMonth`
- `startMonth`
- `startYear`

> The `PhpCalendar` class also defines a `__toString()` method that simply returns its own `$html` property (HTML calendar)

### Example of HTML calendar

[](#example-of-html-calendar)

```

                January
                1970

                MonTueWedThuFriSatSun

                    29

                    30

                    31

                    1

                    2

                    3

                    4
            ...

    ...

```

### Example of 12-month calendar

[](#example-of-12-month-calendar)

```

body {text-align: center;} table {margin: auto;}

body {text-align: center;} table {margin: auto;}
