<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Calendar Table </title>
<?php
$MONTH = Array ("All", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$enMONTH = Array ("January", "February", "Marcy", "April", "may", "June", "July", "August", "September", "October", "N Ovember "," December ");
$WEEK = Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$BACKCOLOR = Array ("#FFC", "#FFF", "#9F6", "#FFC", "#6F0", "#6F6", "#F90", "#F06", "#F00", "#FC3", "#FF6", "#F9 9 ");
function Printmon ($year, $mon)
{
Date_default_timezone_set ("Asia/shanghai");
Global $MONTH;
Global $enMONTH;
Global $WEEK;
Global $BACKCOLOR;
$startdate =strtotime ("1 $enMONTH [$mon] $year"); Gets the date of the query
$enddate = Strtotime ("+1 month", $startdate); Gets the start date for the next one months as a deadline for the monthly calendar output
$theDate = getdate ($startdate); Convert date to string format
$color = $BACKCOLOR [$mon]; Set the background color for a month calendar
Echo ("<table border=\" 1\ "cellspacing=\" 0\ "cellpadding=\" 0\ "bgcolor=\" $color \ ">");
$ym = $year. "Year". $MONTH [$mon];
Echo ("<caption>Echo ("<tr>");
for ($i =0; $i <7; $i + +)//output Day of the week
{
Echo ("<td width=\" 90\ ", height=\" 40\ "align=\" Center\ ">");
Echo ("Echo ("</td>");
}
Echo ("</tr>");
$theWeek = $theDate [wday];//determines the day of the week
for ($i =0; $i <6; $i + +)
{
Echo ("<tr>");
for ($j =0; $j <7; $j + +)
{
Echo ("<td width=\" 90\ ", height=\" 40\ "align=\" Center\ ">");
if ($startdate < $enddate && $theWeek = = $j)//Output the date to the corresponding day of the week, and be careful not to exceed this month's date
{
$theDay = $theDate [Mday];
Echo ("$startdate = Strtotime ("+1 Day", $startdate); Date moved forward 1 days
$theDate = getdate ($startdate);//Update date
$theWeek = ($theWeek + 1)% 7;//Update week
}
Echo ("</td>");
}
Echo ("</tr>");
if ($startdate = = $enddate)//If the full date has been output, end the loop
{
$i = 6;
}
}
Echo ("</table");
}
?>
<body>
<form method= "POST" action= "<?php echo $_server[' php_self '];? > ">
<input type= "text" name= "Myyear" > Year <input type= "text" name= "Mymonth" > Month
<input type= "Submit" >
</form>
<?php
$year = $_post[' myyear ');
$month = $_post[' mymonth ');
if (Is_numeric ($year) && $year >= 1970 && $year <2038)
{
if (Is_numeric ($month) && $month >= 1 && $month <=12)
{
Printmon ($year, $month);
}
else if ($month! = NULL)
{
Echo ("Month is wrong".) "<br/>");
}
}
else if ($year! = NULL)
{
Echo ("Wrong Year".) "<br/>");
}
?>
</body>
PHP Learning Notes Calendar table