calendar.php
?
/*******************************
* A function to determine whether a leap year
* Can be improved according to more complex algorithms *
*******************************/
function Leap_year ($year)
{
if ($year% 4 = 0)//Basic rule
{
return true; is leap year
}
Else
{
return false;
}
}
/*******************************
* Assign operations to some variables *
* Pay special attention to the February assignment *
*******************************/
function Setup ()
{
Global $mon _num;
$mon _num=array (31,30,31,30,31,30,31,31,30,31,30,31);
Global $mon _name;
$mon _name=array ("One", "two", "three", "four",
"Five", "six", "seven", "eight",
"Nine", "Ten", "11", "12");
if (Leap_year ($firstday [year]))//Basic rule
{
$mon _num[1]=29; is leap year
}
Else
{
$mon _num[1]=28;
}
}
/*******************************
* Display a grid in the table *
* Display the content and color variable *
*******************************/
function ShowLine ($content, $show _color)
{
$begin _mark = "<td width=60 height=25>";
$begin _mark = $begin _mark. " <font color= $show _color> ";
$end _mark = "</FONT></TD>";
Echo $begin _mark. $content. $end _mark;
}
?>
The formal commencement of the <!--calendar program-->
<title>
Community Calendar
</title>
<meta http-equiv=content-type content= "text/html; charset=gb2312 ">
<body>
?
Get the current date
$firstday = getdate (Mktime (0,0,0,date ("M"), 1,date ("Y")));
Setup ();
Show the name of the table
echo "<CENTER>";
echo "<table border=2 cellspacing=4>";
echo "<th colspan=7 height=50>";
echo "<font color=red size=3 >";
echo "$firstday [year] years  ". $mon _name[$firstday [mon]-1]. " Monthly &NBSP Calendar ";
echo "</FONT>";
echo "</TH>";
Table header
$weekDay [0] = "Day";
$weekDay [1] = "one";
$weekDay [2] = "two";
$weekDay [3] = "three";
$weekDay [4] = "four";
$weekDay [5] = "Five";
$weekDay [6] = "Six";
echo "<tr align=" center "valign=" Center ">";
Show first row of table
for ($dayNum = 0; $dayNum < 7; + + $dayNum) {
ShowLine ($weekDay [$dayNum], "red");
}
echo "</TR>";
$toweek = $firstday [wday];//The first day of the month is the week
$lastday = $mon _num[$firstday [mon]-1];//The last day of the month is the week
$day _count = 1;//The number of days that should currently be displayed
$up _to_firstday = 1;//Whether to show the first day of the month
for ($row = 0; $row <= ($lastday + $toweek-1)/7; + + $row)//A few weeks this month
{echo "<tr align=center valign=center>";
for ($col =1; $col <=7; + + $col)
{
The first day of the show was "empty."
if ($up _to_firstday <= $toweek) | | ($day _count> $lastday))
{
echo "<TD> </TD>";
$up _to_firstday++;
}
Else
{
Show one day of the month
ShowLine ($day _count, "Blue");
$day _count++;
}
}
echo "</TR>";
}
echo "</TABLE>";
echo "</CENTER>";
?>
</body>