Time to write a calendar program, only focus on the function and implementation of ideas, so the code and functions are relatively simple, but understanding and extension is easier.
The show () function is used to display the calendar, and you can modify the show () function to display a different date by passing a value.
<?php class calendar{Public $weekarray = Array (' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '); Public $firstDay = ";//The first day of the month public $firstNum =";//Returns the weekday number of the first day of the month public $firstDayNum = ";//The first day of the month corresponds to the Chinese week /** * Day of the week * eg: $date = ' 2014-07-21 ' */Public Function Getweek ($date) { $date = Strtotime ($date); the//strtotime () function resolves the datetime description of any English text to a Unix timestamp $num = Date (' W ', $date);//number of days of the week, such as: "0" (Sunday) to "6" (Saturday) return $num; }/** * Gets the number of days of the specified month * eg: $month = ' 2014-07 ' */Public Function Getmonthnum ($month) { $month = Strtotime ($month); Return date (' t ', $month);//The number of days in the specified month}/** * Display calendar */Public function show () { Gets the current date $year = Date (' Y '); $month = Date (' m '); $day = Date (' d '); Echo ' <table border= "1" style= "text-align:center;" > '; Echo ' <tr><td colspan= ' 7 > '. $year. '-' $month. ' </td></tr> '; Echo ' <tr><th> Sunday </th><th> Monday </th><th> Tuesday </th><th> Wednesday </th ><th> Thursday </th><th> Friday </th><th> Saturday </th></tr> '; The number of days to get the current month $yearMonth = ' $year. ' -". $month"; $monthNum = $this->getmonthnum ($yearMonth); Get the first day of the current month is the days of the week $this->firstday = $year. " -". $month." -01 "; $this->firstnum = $this->getweek ($this->firstday); $this->firstdaynum = $this->weekarray[$this->firstnum]; Echo ' <tr> '; for ($i =1; $i <= $monthNum + ($this->firstnum); $i + +) {echo ' <td> '; if ($i >= $this->firstnum+1) {$a = $i-$this->firstnum; if ($a = = $day) {echo ' <div stylE= "Background-color:blue;color: #fff;" > '. $a. ' </div> '; }else{echo ' <div> ' $a. ' </div> '; }} echo ' </td> '; if ($i%7 = = 0) {//Each output 7 columns will be replaced by a line of Echo ' </tr> '; }} echo ' </table> '; }} $calendar = new calendar (); $calendar->show ();
:
The show () function is used to display the calendar, and you can modify the show () function to display a different date by passing a value.
Extended:
The main point of this article is the use of the PHP date () function
Here is an explanation of the date () function: http://wenku.baidu.com/link?url=OPDGzaCMWgjDE0ya8QlDbLIXX0c11ohUjsoLyRm-cYp7lz-O_ 7h4xbilv8jfomhbnsxxsw0fhqxybk0_gn8nr77xmwp-_st7v8ayecbnzjg