PHP Calender
PHP script to display an auto generated calendar:
<?php
$date =time () ;
$day = date('d', $date) ;
$month = date('m', $date) ;
$year = date('Y', $date) ;
$first_day = mktime(0,0,0,$month, 1, $year) ;
$title = date('F', $first_day);
$day_of_week = date('D', $first_day) ;
switch($day_of_week){
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sat": $blank = 6; break;
}
$days_in_month = cal_days_in_month(0, $month, $year) ;
echo "<table border=1 width=294>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=42>S</td><td width=42>M</td><td
width=42>T</td><td width=42>W</td><td width=42>T</td><td
width=42>F</td><td width=42>S</td></tr>";
$day_count = 1;
echo "<tr>";
while ( $blank > 0 )
{
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
while ( $day_num <= $days_in_month )
{
echo " $day_num ";
$day_num++;
$day_count++;
if ($day_count > 7)
{
echo "";
$day_count = 1;
}
}
while ( $day_count >1 && $day_count <=7 )
{
echo "<td> </td>";
$day_count++;
}
echo "</tr></table>";
?>
/*To finish our calendar we use one last while loop. This one fills in the rest
of our calendar with blank table details if needed. Then we close our table.*/
So that's it, all done! Tested and working... Emerald Kweks: Twitter: @_sirkweks.