Simple php 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, month/Day 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, you can automatically select the previous year or the 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. ="
N ";$ Html. ="
| Last month |
{$ This-> Y} year {$ this-> M} month |
Next month |
N ";$ Html. ="
| Sunday |
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |
N ";$ Html. ="
N ";$ First = $ this-> first ();For ($ I = 0; $ I <$ first; $ I ++ ){$ Html. ="
| ";}$ 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. ="
$ I | ";If ($ I = 7% $ first | ($ I + $ first) % 7 = 0) & $ I <$ count ){$ Html. ="
N
";}}$ Count = 7-$ count % 7;If ($ count <7 ){For ($ I = 0; $ I <$ count; $ I ++ ){$ Html. ="
| ";}}$ Html. ="
N ";$ Html. ="
N ";
Return $ html;
}
}
$ Calendar = new Calendar ();
$ Calendar-> set (time ());
Echo $ calendar-> html ();
Week, the current date and today are the day of the week, whether it is a leap year, you can automatically select the previous year or next year, month and day...