| px | top | add code | search | signup | login | help |
<?
/* Change to month/year to display */
$month = 1;
$year = 2000;
/* How to display the titles on the header of the calendar */
$week_titles[] = "Sunday";
$week_titles[] = "Monday";
$week_titles[] = "Tuesday";
$week_titles[] = "Wednesday";
$week_titles[] = "Thursday";
$week_titles[] = "Friday";
$week_titles[] = "Saturday";
/* determine total number of days in a month */
$totaldays = 0;
while ( checkdate( $month, $totaldays + 1, $year ) )
$totaldays++;
/* build table */
echo '<table border="1" cellpaddig="5" cellspacing="5" width="100%"><tr>';
for ( $x = 0; $x < 7; $x++ )
echo '<th><b><font face="Arial">', $week_titles[ $x ], '</font></b></th>';
/* ensure that a number of blanks are put in so that the first day of the month
lines up with the proper day of the week */
$offset = date( "w", mktime( 0, 0, 0, $month, $day, $year ) ) + 1;
echo '<tr>';
if ( $offset > 0 )
echo str_repeat( "<td> </td>", $offset );
/* start entering in the information */
for ( $day = 1; $day <= $totaldays; $day++ )
{
echo '<td>', $day, '</td>';
$offset++;
/* if we're on the last day of the week, wrap to the other side */
if ( $offset > 6 )
{
$offset = 0;
echo '</tr>';
if ( $day < $totaldays )
echo '<tr>';
}
}
/* fill in the remaining spaces for the end of the month, just to make it look
pretty */
if ( $offset > 0 )
$offset = 7 - $offset;
if ( $offset > 0 )
echo str_repeat( "<td> </td>", $offset );
/* end the table */
echo '</td></table>';
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.