Here's the complete script
Code: Select all
<?php
//array of months
$months = array(
'January' => 1,
'February' => 2,
'March' => 3,
'April' => 4,
'May' => 5,
'June' => 6,
'July' => 7,
'August' => 8,
'September' => 9,
'October' => 10,
'November' => 11,
'December' => 12
);
$monthsF = array_flip($months);
//is this a leap year?
$leapYear = ((date('Y') % 4) == 0);
//current month and year
$currentMonth = date('n');
$currentYear = date('Y');
//number of days in each month
$monthDays = array(
1 => range(1, 31),
2 => $leapYear ? range (1, 29) : range(1, 28),
3 => range(1, 31),
4 => range(1, 30),
5 => range(1, 31),
6 => range(1, 30),
7 => range(1, 31),
8 => range(1, 31),
9 => range(1, 30),
10 => range(1, 31),
11 => range(1, 30),
12 => range(1, 31)
);
for ($month = $currentMonth; $month < $currentMonth + 3 ; $month++)
{
//what day does the first of the month fall on?
$startDayOfWeek = date('w', mktime(0, 0, 0, $month, 1, $currentYear));
//start the table
echo '<table cellspacing="0" cellpadding="2" border="0" style="border: solid 1px #000;">
<tr>
<td colspan="7" align="center" style="border-bottom: solid 1px #000;">' . $monthsF[$month] . '</td>
</tr>
<tr>
<td>Sun</td>
<td>Mon</td>
<td>Tue</td>
<td>Wed</td>
<td>Thu</td>
<td>Fri</td>
<td>Sat</td>
</tr>';
//show blank table cells till first day of month occurs
for ($i = 0; $i < $startDayOfWeek; $i++)
{
echo '<td> </td>';
}
//start the iteration at the number of days till the first day of the month occurs
$it = $startDayOfWeek;
//loop through the month's worth of days
foreach ($monthDays[$month] AS $day)
{
if ($it == 7)
{
echo '</tr><tr>';
$it = 0;
}
echo '<td align="center">' . $day . '</td>';
$it++;
}
//end the table
echo '</table><br />';
}Code: Select all
for ($month = $currentMonth; $month < $currentMonth + 3 ; $month++)