This article mainly introduces the use of PHP calendar, the following have effect map, we refer to the use of the bar
calendar.class.php Code is as follows: <?php class Calendar { private $year;//Current year private $month;//Current Month Private $start _weekday; The first day of the month corresponds to the week private $days; How many days are there in the current month function __construct () { $this->year=isset ($_get["year")? $_get["Year"]: Date ("Y"); $this->month=isset ($_get["month"])? $_get["Month"]: Date ("M"); $this->start_weekday=date ("W", Mktime (0, 0, 0, $this->month, 1, $this->year)); $this->days=date ("T", mktime (0, 0, 0, $this->month, 1, $this->year)); } function out () { echo ' <table align= ' center ' > '; $this->chagedate ("test.php"); $this->weekslist (); $this->dayslist (); echo ' </table> '; } Private function weekslist () { $week =array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six '); echo ' <tr> '; &NBSPFor ($i =0 $i <count ($week), $i + +) echo ' <th class= ' fontb ' > '. $week [$i]. ' </th> '; echo ' </tr> '; } Private function dayslist () { echo ' <tr> '; //output space (to be vacated before the first day of January) &NB Sp for ($j =0 $j < $this->start_weekday; $j + +) echo ' <td> </td> '; for ($k =1 $k <= $this->days; $k + +) { $j + + if ($k ==date (' d ')) &NB Sp echo ' <td class= ' fontb ' > '. $k. ' </td> '; Else echo ' <td> '. $k. ' </td> '; if ($j%7==0) echo ' </tr><tr> '; &NBSP} //after several spaces while ($j%7!==0) { echo ' <td> </td> ;'; $J + +;   echo ' </tr> '; } Private function prevyear ($year, $month) { $year= $year-1; if ($year < 1970) $year = 1970; return "year={$year}&month={$month}"; } Private Function Prevmo Nth ($year, $month) { if ($month = = 1) { $year = $year-1; if ($year < 1970 ) $year = 1970; $month = 12; }else{ $month-- } return "year={$year}&month={$month}"; } Private Function nextyear ($year, $month) { $year = $year + 1; &nbs P if ($year > 2038) $year = 2038; return "year={$year}&month={$month}"; } Private Function Nextmo Nth ($year, $month) { if ($month ==12) { $year + + ($year > 2100) &N Bsp $year = 2100; $month = 1; &NBSP;} else{ $month + + return "year={$year}&month={$month}"; nbsp } Private function chagedate ($url = "") { echo ' <tr> '; echo ' <td>& Lt;a href= "? '". $this->prevyear ($this->year, $this->month). " > '. ' << '. ' </a></td> '; echo ' <td><a href= '? $this->prevmonth ($this->year, $this->month). " > '. ' < '. ' </a></td> '; echo ' <td colspan= ' 3 ' > '; echo ' <form> '; echo ' <select name= ' year ' onchange= ' window.location= '. $url. Year= ' +this.options[selectedindex].value+ ' &month= '. $this->month. ' " > '; for ($sy =1970 $sy <= 2100 $sy + +) { $selected = ($sy = = $this->year)? "Selected": ""; echo ' <option '. $selected. ' value= '. $sy. ' " > '. $sy. ' </option> ';   echo ' </select> '; echo ' <select name= ' month ' onchange= ' window.location= '. $url. ' Year= '. $this->year. ' &month= ' +this.options[selectedindex].value ' > '; for ($sm =1 $sm <=12; $sm + +) { $selected 1 = ($sm = = $this->month)? "Selected": ""; echo ' <option '. $selected 1. ' value= '. $sm. ' > ' $sm. ' </option> ';   echo ' </select> '; echo ' </form> '; echo ' </td> '; echo ' <td><a href= '? $this->nextyear ($this->year, $this->month). " > '. ' >> '. ' </a></td> '; echo ' <td><a href= '? $this->nextmonth ($this->year, $this->month). " > '. ' > '. ' </a></td> '; echo ' </tr> '; } &NBSP}?> test.php code as follows: <style> table { border:1px solid #050;  } &NBSP;.FONTB { Color:white; Background:blue; &NBSP} th { width:30px; } td,th { height:30px; Text-align:cen ter &NBSP} form { margin:0px padding:0px } </style> <?php include "Calendar . class.php "; $calendar =new calendar; $calendar->out ()?>