PHP handwritten calendar code
[PHP] code
$ Monthnow = isset ($ _ GET ['mon'])? $ _ GET ['mon']: date ("n"); $ yearnow = isset ($ _ GET ['Year'])? $ _ GET ['Year']: date ("Y"); if ($ monthnow = 13) {$ monthnow = 1; $ yearnow = $ yearnow + 1 ;} if ($ monthnow = 0) {$ monthnow = 12; $ yearnow = $ yearnow-1;} $ mdays = date ("t "); // total number of days in the current month $ datenow = date ("j"); // date of the current day // calculate the number of days in the first day of the current month $ wk1st = date ("w", mktime, 0, $ monthnow, 1, $ yearnow); $ trnum = ceil ($ mdays + $ wk1st)/7 ); // calculate the number of rows in the table // The Table string $ tabstr ="
". $ Dayecho ."
"; $ Tabstr. ="
| < |
"; $ Tabstr. = $ yearnow. 'year'. $ monthnow. 'month'. date ('D', time ()." |
"; $ Tabstr. =" >>> |
"; $ Tabstr. ="
| Day |
I |
II |
3. |
Thu |
V. |
Sat. |
"; For ($ I = 0; $ I <$ trnum; $ I ++) {$ tabstr. ="
"; // Seven cells in each row for ($ k = 0; $ k <7; $ k ++) {// Obtain the cell sequence number $ tabidx = $ I * 7 + $ k; // if the cell sequence number is less than the number of weeks on the first day of the month ($ wk1st) or greater than (total number of months + $ wk1st), just fill in space, otherwise, write Date ($ tabidx <$ wk1st or $ tabidx> $ mdays + $ wk1st-1 )? $ Dayecho = "& nbsp": $ dayecho = $ tabidx-$ wk1st + 1; // highlight the date of today if ($ dayecho! = '& Nbsp') {$ num = $ dayecho; if ($ dayecho = $ datenow) $ dayecho =""; $ Tabstr. ='
| ";} Else {$ tabstr. ='
'. $ Dayecho ." | ";}}$ Tabstr. ="
";}$ Tabstr. ="
"; Print $ tabstr; // output calendar