Php calendar program, php calendar Program
This example describes the calendar program implemented by php. Share it with you for your reference. The details are as follows:
<? Php /// determine whether $ Year and $ Month are empty. If they are empty, the current date of the system is obtained, otherwise, use $ _ GET to GET $ Year = empty ($ _ GET ['Year'])? Date ("Y"): $ _ GET ["Year"]; $ Month = empty ($ _ GET ['month'])? Date ("m"): $ _ GET ["Month"]; // GET the current date /// $ Today = date ("Ymj "); //// initialization date array //// $ 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 the array of weeks /// $ Weekday = array ("<font color = 'red'> Sun </font>", "Mon", "Tue ", "Wed", "Thu", "Fri", "<font color = 'red'> Sat </font>"); $ Week Day_count = count ($ Weekday); $ daynum = 0; $ space = "<td> </td>"; $ col = 0; //// print the 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;?> & Amp; 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;?> & Amp; Month = <? Php echo $ Month?> "OnClick =" javascript: document. linked. submit (); "name =" Year ">>></a> </td> <td colspan = 3 align = center> <a href = "? Year = <? Php echo $ Year?> & Amp; Month = <? Php if ($ Month-1> 0) if ($ Month-1 <10) 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?> & Amp; 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> <td colspan =" 8 "> </td> </tr> <tr> <? Php /// print the weekly list /// while (list (, $ Weekvalue) = each ($ Weekday) echo "<td align = center> ". $ Weekvalue. "</td>"; echo "</tr>"; // print the date list //// when the month is, delete a value from the end of the array, that is, delete the value 31. if ($ Month = 4 or $ Month = 6 or $ Month = 9 or $ Month = 11) {array_pop ($ Maxday); $ Maxday_count --;} // first judge whether the month is February. If yes, then judge whether the year is a leap year. If yes, remove two values from the end of the array; otherwise, remove three values. if ($ Month = 2) {if ($ Year % 4 = 0) {array_pop ($ Maxday); array_pop ($ Maxda Y); $ Maxday_count-= 2;} else {array_pop ($ Maxday); $ Maxday_count-= 3 ;}} //// print the date //// while ($ daynum <$ Maxday_count) {echo "<tr>"; while (list ($ colnum, $ Dayvalue) = each ($ Maxday) {// determines the day of the current day of the week $ DayWeek = date ("w", strtotime ($ Year. "-". $ Month. "-". $ Dayvalue); // when the current date is at 1st, that is, the first day of each month, add the corresponding blank grid if ($ Dayvalue = 1) in front of it) for ($ I = 0; $ I <$ DayWeek; $ I ++) echo $ space; // print Several blank grids $ daynum ++ each month; // compare them with the current date string when printing the date. If they are equal, the font is marked in red. if ($ Year. $ Month. $ Dayvalue = $ Today) {$ u1 = "<B> <u>"; $ u2 = "</B> </u> ";} else {$ u1 = ""; $ u2 = "";} if ($ DayWeek = 0 or $ DayWeek = 6) $ color = "red "; else $ color = "black"; echo "<td align = center> <font color = ". $ color. "> ". $ u1. $ Dayvalue. $ u2. "</font> </td>"; // Add 1 to the value of day of the week. If it is a multiple of 7, wrap the line and exit the loop (line feed) if ($ DayWeek + 1) % 7 = 0) {$ col ++; break;} Echo "</tr>" ;}?>
The running effect is as follows:
I hope this article will help you with php programming.