PHP Calendar

A PHP class that makes generating calendars as easy as possible.


You can use the addEvent() or addEvents() methods to mark events on the generated calendar.


This is fully compatible with PHP 5 through to PHP 7.3+


GitHub/BitBucket


Installation via Composer

You can now install this class via composer:

composer require benhall14/php-calendar

Remember to add the composer autoloader before using the class and use the correct namespace.

require 'vendor/autoload.php'; use benhall14\phpCalendar\Calendar as Calendar;

Usage

Please make sure you have added the required classes.

You should probably also make sure you include the calendar.css stylesheet, unless you are creating your own stylesheet.

<link rel="stylesheet" type="text/css" href="css/calendar.css">

In its simplest form, use the following to create a calendar:

# create the calendar object $calendar = new Calendar(); # if needed, add event $calendar->addEvent( '2017-01-14', # start date in Y-m-d format '2017-01-14', # end date in Y-m-d format '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 included on the event days ); # or for multiple events $events = array(); $events[] = array( 'start' => '2017-01-14', 'end' => '2017-01-14', 'summary' => 'My Birthday', 'mask' => true, 'classes' => ['myclass', 'abc'] ); $events[] = array( 'start' => '2017-12-25', 'end' => '2017-12-25', 'summary' => 'Christmas', 'mask' => true ); $calendar->addEvents($events); # finally, to draw a calendar echo $calendar->draw(date('Y-m-d')); # draw this months calendar # this can be repeated as many times as needed with different dates passed, such as: echo $calendar->draw(date('Y-01-01')); # draw a calendar for January this year echo $calendar->draw(date('Y-02-01')); # draw a calendar for February this year echo $calendar->draw(date('Y-03-01')); # draw a calendar for March this year echo $calendar->draw(date('Y-04-01')); # draw a calendar for April this year echo $calendar->draw(date('Y-05-01')); # draw a calendar for May this year echo $calendar->draw(date('Y-06-01')); # draw a calendar for June this year # to use the pre-made color schemes, include the calendar.css stylesheet and pass the color choice to the draw method, such as: echo $calendar->draw(date('Y-m-d')); # print a (default) turquoise calendar echo $calendar->draw(date('Y-m-d'), 'purple'); # print a purple calendar echo $calendar->draw(date('Y-m-d'), 'pink'); # print a pink calendar echo $calendar->draw(date('Y-m-d'), 'orange'); # print a orange calendar echo $calendar->draw(date('Y-m-d'), 'yellow'); # print a yellow calendar echo $calendar->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

Demo

January 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
February 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
March 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
April 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
May 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
June 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
July 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
August 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
September 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
October 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
November 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
December 2019
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Requirements

Fully tested to work with PHP 5.3, 5.5, 5.6, 7.0, 7.1, 7.2 and 7.3

PHP DateTime


License

Copyright (c) Benjamin Hall, ben@conobe.co.uk https://conobe.co.uk

Licensed under the MIT license


If you find this project helpful or useful in any way, please consider getting me a cup of coffee - It's really appreciated :)

Donate

More Projects?
Benjamin, is brilliant at what he does, he really knows what he is at. Gives real useful advice and guidance. He is fast and timely provides updates and always provides solutions and listens well. Trust me Benjamin is a breath of fresh air.

- Alexander T.

★★★★★

Ben had a great idea for my project and completed the project to our requirements very quickly. He also helped me tweak a few issues and answered my questions quickly. We'll work with Ben again!

- Gordon S.

★★★★★

I was impressed: a freelancer who could give me inputs and details on how he'd implement the solution, kept me updated in the meanwhile, understood my requirements and proposed pretty nice tweaks to make things even better. Ben, you are amazing. I will need no more time to find any other dev's, and will surely deal with you again if I need something related to these things in the future. Full stop.

- Marco F.

★★★★★

Absolutely superb, a great work ethic, outstanding knowledge and a great eye for detail. I thoroughly recommend him!

- Gary J.

★★★★★

Benjamin is a talented developer who can tackle technically challenging projects with great service and communication. Thoroughly recommended.

- Steven M.

★★★★★

Ben truly went above and beyond. He's fantastic at communication, coding, getting round problems, fixing issues, WordPress, custom plugins and much more. I will be using Ben again for other projects.

- Rachael R.

★★★★★

Ben went the extra mile and not only resolved the problem but provided a more suitable solution for the long term. Cheers!

- William R.

★★★★★

Ben is an amazing developer. He took the project and delivered it on time and within budget, whilst maintaining excellent communication. He also worked beyond what was asked to make sure the project was functioning correctly. Would highly recommend A++++!

- David B.

★★★★★

Fantastic work on our JS script. Ben worked beyond the goals of the project and overcame extra issues that were not defined in the project. He is very quick to respond and patent when waiting for our response. One of our top 5 Developers, We had to deal with many Interfaces including server firewalls/Java-scripting/JSON/PHP/PHP APIs/Remote Databases and automation.

- Kevin J.

★★★★★

Ben is just great to work with. Efficient, clearly communicating, understanding very quickly, and also giving great advice. I will continue working with Ben on any other WordPress stuff. Sorry for all those other PPH'ers :-)

- Bruno V.

★★★★★

Absolutely amazing experience. Ben is an expert in this field, I was amazed at how quickly he jumped on our platform and decoded the code, db etc. He will go over and above to find solutions for clients. Highly recommended.

- Harrus A.

★★★★★

Interested in working together to make something great? Hire CONOBE