This article is mainly an original php calendar control written by a beginner in php. It can display the current date and today's day of the week, whether it is a leap year, and automatically select the previous or next year, the same is true for month and date.
Simple php tutorial calendar control code example
/*
This article is mainly an original php calendar control written by a beginner in php. It can display the current date and today's day of the week, whether it is a leap year, and automatically select the previous or next year, the same is true for month and date.
*/
Date_default_timezone_set ("Etc/GMT-8 ");
Class Calendar {
Var $ T = array ();
Var $ datesOFmonth = array ('1' => '31', '2' => '28', '3' => '31 ', '4' => '30', '5' => '31', '6' => '30', '7' => '31 ', '8' => '31', '9' => '30', '10' => '31', '11' => '30 ', '12' => '31 ');
Var $ Y, $ M, $ D;
Function set ($ time ){
$ This-> T = getdate ($ time );
$ This-> Y = $ this-> T ['Year'];
$ This-> M = $ this-> T ['mon'];
$ This-> D = date ('D', $ time );
}
Function isRun (){
Return ($ this-> Y % 400 = 0 | ($ this-> Y % 4 = 0 & $ this-> Y % 100 = 0 ))? 1: 0;
}
Function first (){
$ Time = mktime (0, 0, 0, $ this-> M, 1, $ this-> Y );
$ Time = getdate ($ time );
Return $ time ['wday'];
}
Function html (){
$ IsRun = $ this-> isRun ();
$ This-> datesOFmonth [2] = $ isRun = 1? 29: 28;
$ Html. = "<table style = 'border: solid 1px black; '> n ";
$ Html. = "<tr> <th> <a href =''> last month </a> </th> <th colspan = '5' >{$ this-> Y} year {$ this-> M} month </th> <a href = ''> next month </a> </th> <tr> n ";
$ Html. = "<tr> <td> Sunday </td> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> thursday </td> <td> Friday </td> <td> Saturday </td> </tr> n ";
$ Html. = "<tr> n ";
$ First = $ this-> first ();
For ($ I = 0; $ I <$ first; $ I ++ ){
$ Html. = "<td> </td> ";
}
$ Count = $ this-> datesOFmonth [$ this-> M] + $ first;
For ($ I = 1; $ I <= $ this-> datesOFmonth [$ this-> M]; $ I ++ ){
$ Style = $ I ==$ this-> D? 'Style = "color: red; font-weight: bold ;"':'';
$ Html. = "<td align = 'center' {$ style}> $ I </td> ";
If ($ I = 7% $ first | ($ I + $ first) % 7 = 0) & $ I <$ count ){
$ Html. = "</tr> n <tr> ";
}
}
$ Count = 7-$ count % 7;
If ($ count <7 ){
For ($ I = 0; $ I <$ count; $ I ++ ){
$ Html. = "<td> </td> ";
}
}
$ Html. = "</tr> n ";
$ Html. = "</table> n ";
Return $ html;
}
}
$ Calendar = new Calendar ();
$ Calendar-> set (time ());
Echo $ calendar-> html ();