In this tutorial I will show you how to create a calendar script in PHP on Tuesday 13 February 2007 by Administrator in Tutorials hits: 114422
In this tutorial I will show you how to create a calendar script in PHP. We will create a simple but good looking - easy customizable via CSS - calendar table.
[html] In this tutorial I will show you how to create a calendar script in PHP. We will create a simple but good looking - easy customizable via CSS - calendar table.
Step 1. First of all try to collect the necessary information which are important to display the actual month and highlight the actual day. Besides this we want to display the actual month and year informations as well. To do this we need 3 special days informations:
The actual day
The first day of the actual month
The last day of the actual month
With the above mentioned informations we can decide what day was the first day, how long is the month and of course which is the actual day.
Step 2. To get the information mentioned in Step 1 we will use the PHP built in function: getdate(). Without parameters this function returns the actual day informations in an array as follows:
To get the last day of the month with getdate we need to try to get the 0. day of the next month. So the code to get the information looks like this: <?php $today = getdate(); $firstDay = getdate(mktime(0,0,0,$today['mon'],1,$today['year'])); $lastDay = getdate(mktime(0,0,0,$today['mon']+1,0,$today['year'])); ?>