$selectedDay = Date (' d ');
$selectedMonth = Date (' m ');
$selectedYear = Date (' Y ');
Gets the first day of the month is the numeric type of the week
$firstday = Date (' W ', Mktime (0,0,0, $selectedMonth, 1, $selectedYear));
Find out the last day of this month
$lastday = 31;
do {
$monthOrig = Date (' m ', Mktime (0,0,0, $selectedMonth, 1, $selectedYear));
$monthTest = Date (' m ', Mktime (0,0,0, $selectedMonth, $lastday, $selectedYear));
if ($monthTest! = $monthOrig) {$lastday-= 1;}
} while ($monthTest! = $monthOrig);
Get the corresponding English name for the month
$monthName = Date (' F ', Mktime (0,0,0, $selectedMonth, 1, $selectedYear));
Display the calendar header
$days = Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$dayRow = 0;
Print ("
"); Print ("
$monthName $selectedYear
"); Print ("
\ n "); for ($i =0; $i <=6; $i + +) {print ("
| $days [$i] | \ n "); } print ("
\ n "); Print ("
\ n "); Empty in front of the first day of the month ($dayRow < $firstday) {print ("
| | "); $dayRow + = 1; } $day = 0; while ($day < $lastday) {//The following judgment statement is used to convert each display 7 time position to the next line if (($dayRow% 7) = = 0) {print ("
\ n
\ n "); } $adjusted _day = $day +1;//The date of the day is shown in red if ($adjusted _day== $selectedDay) {echo]
| $adjusted _day | ";} Else{echo "
$adjusted _day | ";} $day + = 1; $dayRow + = 1; } print ("\ n
\ n
");
?>