<?php
<-------handle variables submitted through the Get method; start-------->
if ($HTTP _get_vars[year]== "")
{
$HTTP _get_vars[year]=date ("Y");
}
if ($HTTP _get_vars[month]== "")
{
$HTTP _get_vars[month]=date ("n");
}
$month = $HTTP _get_vars[month];
$year = $HTTP _get_vars[year];
<-------handle variables submitted through the Get method; end-------->
if ($year <1971)
{
echo "Error!";
echo "<BR>";
echo "<a href= $HTTP _server_vars[php_self]>back</a>";
Exit ();
}
?>
<table width= "border=" 1 "cellspacing=" 0 "cellpadding=" 0 "bordercolor=" #E7E7E7 "style=" font-size:12px; "align= "Center" >
<TR align= "center" ><td colspan= "2" >
<?php
<-------the processing of the month exceeding 1 to 12 o'clock; start------->
if ($month <1)
{
$month = 12;
$year-=1;
}
if ($month >12)
{
$month = 1;
$year +=1;
}
<-------the processing of the month exceeding 1 to 12 o'clock; end------->
//***************************************
<---------last year, next year, last month, next month's connection processing and output; start--------->
echo "<a href= $HTTP _server_vars[php_self]?year=". ($year-1). " &month= ". $month." ><<</a> year <a href= $HTTP _server_vars[php_self]?year= ". ($year + 1). " &month= ". $month." >>></a> ";
?>
</TD><TD colspan= "3" ><?php echo $year. " Year ". $month." Month ";? >
</TD><TD colspan= "2" >
<?php
echo "<a href= $HTTP _server_vars[php_self]?month=". ($month-1). " &year= ". $year." ><<</a> month <a href= $HTTP _server_vars[php_self]?month= ". ($month + 1). " &year= ". $year." >>></a> ";
<--------last year, next year, last month, next month's connection processing and output; end--------->
?></td></tr>
<tr align=center><td><font color= "Red" > Day </font></td><td> one </td>< Td> two </td><td> three </td><td> four </td><td> five </td><td> six </td>< /tr><tr>
<?php
$d =date ("D");
$FirstDay =date ("W", Mktime (0,0,0, $month, 1, $year));//The number of days to obtain any one months is the day of the week, and the number of numbers used to calculate is the beginning of the first grid of the table
$bgtoday =date ("D");
function Font_color ($month, $today, $year)//used to calculate the font color for Sunday
{
$sunday =date ("W", Mktime (0,0,0, $month, $today, $year));
if ($sunday = = "0")
{
$FontColor = "Red";
}
Else
{
$FontColor = "BLACK";
}
return $FontColor;
}
function bgcolor ($month, $bgtoday, $today _i, $year)//used to calculate the background color of the day
{
$show _today=date ("D", Mktime (0,0,0, $month, $today _i, $year));
$sys _today=date ("D", Mktime (0,0,0, $month, $bgtoday, $year));
if ($show _today== $sys _today)
{
$bgcolor = "Bgcolor= #6699FF";
}
Else
{
$bgcolor = "";
}
return $bgcolor;
}
function Font_style ($month, $today, $year)//php used to calculate the font style for Sunday
{
$sunday =date ("W", Mktime (0,0,0, $month, $today, $year));
if ($sunday = = "0")
{
$FontStyle = "<strong>";
}
Else
{
$FontStyle = "";
}
return $FontStyle;
}
for ($i =0; $i <= $FirstDay; $i + +)//This for is used to output one position of a month
{
for ($i; $i < $FirstDay; $i + +)
{
echo "<td align=center> </td>\n";
}
if ($i = = $FirstDay)
{
echo "<td align=center". bgcolor ($month, $bgtoday, 1, $year). " ><font color= ". Font_color ($month, 1, $year)." > ". Font_style ($month, 1, $year)." 1</font></td>\n ";
if ($FirstDay ==6)//judge whether the number 1th is Saturday
{
echo "</tr>";
}
}
}
$countMonth =date ("T", Mktime (0,0,0, $month, 1, $year));//The total number of days in a month
for ($i =2; $i <= $countMonth; $i + +)//output is positioned by No. 1th and then 2nd until the month of the month
{
echo "<td align=center". bgcolor ($month, $bgtoday, $i, $year). " ><font color= ". Font_color ($month, $i, $year)." > ". Font_style ($month, $i, $year)." $i </font></td>\n ";
if (Date ("W", Mktime (0,0,0, $month, $i, $year)) ==6)//Judge whether the day is Saturday
{
echo "</tr>\n";
}
}
?>
</table>
A PHP calendar program