This article mainly introduces the PHP output calendar table code example. This article provides the code example directly. For more information, see
This article mainly introduces the PHP output calendar table code example. This article provides the code example directly. For more information, see
Calendar<? Php $ MONTH = array ("Lunar January", "January", "February", "March", "April", "May", "June", "July ", "August", "August"); $ enMONTH = array ("August", "January", "February ", "Marcy", "April", "May", "June", "July", "August", "September", "October", "November ", "December"); $ WEEK = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Saturday "); $ BACKCOLOR = array ("# FFC", "# FFF", "#9F6", "# FFC", "#6F0", "#6F6", "# F90 ", "# F06", "# F00", "# FC3", "# FF6", "# F99"); function PrintMon ($ year, $ mon) {date_default_timezone_set ("Asia/Shanghai"); global $ MONTH; global $ enMONTH; global $ WEEK; global $ BACKCOLOR; $ startdate = strtotime ("1 $ enMONTH [$ mon] $ year"); // obtain the query year and month $ enddate = strtotime ("+ 1 month", $ startdate ); // get the start date of the next month as the end time of the calendar output $ theDate = getdate ($ startdate ); // convert the date to the string format $ color = $ BACKCOLOR [$ mon]; // set the background color of the calendar echo ("
"); $ Ym = $ year." year ". $ MONTH [$ mon]; echo ("
$ Ym
"); Echo ("
"); For ($ I = 0; $ I <7; $ I ++) // output the day of the week {echo ("
"); Echo (" $ WEEK [$ I] "); echo (" | ");} Echo ("
"); $ TheWeek = $ theDate [wday]; // determine the day of the week for ($ I = 0; $ I <6; $ I ++) {echo ("
"); For ($ j = 0; $ j <7; $ j ++) {echo ("
"); If ($ startdate <$ enddate & $ theWeek = $ j) // output the date to the column of the corresponding day of the week, do not exceed the current month Date {$ theDay = $ theDate [mday]; echo ("$ theDay"); $ startdate = strtotime ("+ 1 day", $ startdate ); // one day before the date is moved forward $ theDate = getdate ($ startdate); // update date $ theWeek = ($ theWeek + 1) % 7; // update week} echo (" | ");} Echo ("
"); If ($ startdate = $ enddate) // if all dates have been output, end loop {$ I = 6 ;}} echo ("<? Php $ year = $ _ POST ['myyear']; $ month = $ _ POST ['mymonth']; if (is_numeric ($ year) & $ year> = 1970 & $ year <2038) {if (is_numeric ($ month) & $ month> = 1 & $ month <= 12) {PrintMon ($ year, $ month);} else if ($ month! = NULL) {echo ("the month is incorrect "."") ;}} Else if ($ year! = NULL) {echo ("the year is incorrect "."") ;}?>