The example in this article describes the calendar program that PHP implements. Share to everyone for your reference. as follows:
<?php////determine if $year and $month are empty, and if the current date of the system is obtained, otherwise the $_get gets $Year = Empty ($_get[' year '))?
Date ("Y"): $_get["Year"]; $Month = Empty ($_get[' Month '))?
Date ("M"): $_get["Month"];
Gets the current date////$Today = Date ("YMJ"); Initializes an array of dates////$Maxday = Array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");
$Maxday _count = count ($Maxday); Initialize Week array////$Weekday = Array ("<font color= ' Red ' >Sun</font>", "Mon", "Tue", "Wed", "Thu", "Fri", "<
Font color= ' red ' >Sat</font> ');
$Weekday _count = count ($Weekday);
$daynum = 0;
$space = "<td> </td>";
$col = 0; Print table header////?> <form action= "calendar.php" method= "POST" name= "linked" > <TABLE><TR><TD Colspan=3 align=center><a href= "? year=<?php if ($Year-1 > 1900) echo $Year -1;else echo $Year;? >&month=<?php echo $Month?> "onclick=" Javascript:document.linked.submit (); Name= "Year" ><<</a> <?php echo $Year? > <a href= "? year=<?php if ($Year +1 <2999) echo $Year +1;else echo $Year;? >&month=<?php echo $Month?> "onclick=" Javascript:document.linked.submit (); Name= "Year" >>> </a></td> <td> </td><td colspan=3 align=center><a href= "? year=<?php echo $Year >&month=<?php if ($Month-1 >0) if ($Month-1 <) echo "0". ($Month-1); else echo $Month-1; else echo $Month;? > "onclick=" Javascript:document.linked.submit (); "Name=" Month "><<</a> <?php echo $Month;? > <a href= "? year=<?php echo $Year >&month=<?php if ($Month +1 <13) if ($Month +1 <10) echo "0". ($Month + 1); else Echo ($Month + 1); else echo $Month;? > "onclick=" Javascript:document.linked.submit (); "Name= Month" >>></a></td></tr> <TR><TD colspan= "8" ></td></tr><tr> <?php////Print week list////while (list (, $Weekvalue) = each ($WeEkday)) echo "<td align=center> ". $Weekvalue. "
</td> ";
echo "</tr>";
Print date list//////When the month is 4,6,9,11, delete a value from the end of the array, that is, delete the value of 31.
if ($Month = = 4 or $Month = = 6 or $Month = = 9 or $Month = one) {Array_pop ($Maxday);
$Maxday _count--;
//First determine whether the month is February, if yes, then judge whether the year is a leap years, if yes, remove 2 values from the tail of the array, or remove 3 values.
if ($Month = = 2) {if ($Year% 4 = 0) {array_pop ($Maxday);
Array_pop ($Maxday);
$Maxday _count-=2;
else {array_pop ($Maxday);
Array_pop ($Maxday);
Array_pop ($Maxday);
$Maxday _count-=3;
////Print Date////while ($daynum < $Maxday _count) {echo "<tr>"; while (the list ($colnum, $Dayvalue) = each ($Maxday)) {//Determine which day of the week the current date is $DayWeek = Date ("W", Strtotime ($Year.) -". $Month."
-". $Dayvalue)); When the current date is in the 1th, which is the 1th day of the month, the corresponding empty grid if ($Dayvalue = = 1) for ($i =0; $i < $DayWeek; $i + +) echo $space, and print out a few squares per month
Sub $daynum + +;
When the date is printed, it is compared to the current date string, and the font is marked red if equal.
if ($Year. $Month. $Dayvalue = = $Today) {$u 1 = "<b><u>"; $u 2 = "</b></u> ";}
else {$u 1 = "";
$u 2 = "";
if ($DayWeek = = 0 or $DayWeek = = 6) $color = "Red";
else $color = "BLACK"; echo "<td align=center><font color=". $color. " > ". $u 1. $Dayvalue. $u 2."
</font></td> ";
Use this value plus 1 for the day of the week, and if it's a multiple of 7, break out of the loop (line-wrapping printing) if (($DayWeek + 1)% 7 = 0) {$col + +;
Break
} echo "</tr>";
}?>
The operation effect is as follows:
I hope this article will help you with your PHP program design.