Php calendar production code sharing. The code for copying calendar. class. php is as follows :? PhpclassCalendar {private $ year; current year private $ month; current month private $ start_weekday;
Calendar. class. php
The code is as follows:
Class Calendar {
Private $ year; // current year
Private $ month; // The Current month
Private $ start_weekday; // The Day of the month corresponds to the day of the week
Private $ days; // The total number of days in the current month
Function _ construct (){
$ This-> year = isset ($ _ GET ["year"])? $ _ GET ["year"]: date ("Y ");
$ This-> month = isset ($ _ GET ["month"])? $ _ GET ["month"]: date ("m ");
$ This-> start_weekday = date ("w", mktime (0, 0, 0, $ this-> month, 1, $ this-> year ));
$ This-> days = date ("t", mktime (0, 0, 0, $ this-> month, 1, $ this-> year ));
}
Function out (){
Echo'
';$ This-> chageDate ("test. php ");$ This-> weeksList ();$ This-> daysList ();Echo'
';
}
Private function weeksList (){
$ Week = array ('day', 'yi', '2', '3', '4', '5', '6 ');
Echo'';
For ($ I = 0; $ I Echo''. $ Week [$ I].'';
Echo'';
}
Private function daysList (){
Echo'';
// Output space (the space should be blank before the first day of October January)
For ($ j = 0; $ j <$ this-> start_weekday; $ j ++)
Echo' ';
For ($ k = 1; $ k <= $ this-> days; $ k ++ ){
$ J ++;
If ($ k = date ('D '))
Echo''. $ K .'';
Else
Echo''. $ K .'';
If ($ j % 7 = 0)
Echo'';
}
// A few spaces
While ($ j % 7! = 0 ){
Echo' ';
$ J ++;
}
Echo'';
}
Private function prevYear ($ year, $ month ){
$ Year = $ year-1;
If ($ year <1970)
$ Year = 1970;
Return "year = {$ year} & month = {$ month }";
}
Private function prevMonth ($ year, $ month ){
If ($ month = 1 ){
$ Year = $ year-1;
If ($ year <1970)
$ Year = 1970;
$ Month = 12;
} Else {
$ Month --;
}
Return "year = {$ year} & month = {$ month }";
}
Private function nextYear ($ year, $ month ){
$ Year = $ year + 1;
If ($ year> 2038)
$ Year = 2038;
Return "year = {$ year} & month = {$ month }";
}
Private function nextMonth ($ year, $ month ){
If ($ month = 12 ){
$ Year ++;
If ($ year> 2100)
$ Year = 2100;
$ Month = 1;
} Else {
$ Month ++;
}
Return "year = {$ year} & month = {$ month }";
}
Private function chageDate ($ url = ""){
Echo'';
Echo'PrevYear ($ this-> year, $ this-> month). '">'. '<'.'';
Echo'PrevMonth ($ this-> year, $ this-> month). '">'. '<'.'';
Echo'';
Echo '';
Echo'';
Echo'NextYear ($ this-> year, $ this-> month). '">'. '> '.'';
Echo'NextMonth ($ this-> year, $ this-> month). '">'. '> '.'';
Echo'';
}
}
?>
Test. php
The code is as follows:
Include "calendar. class. php ";
$ Calendar = new Calendar;
$ Calendar-> out ();
?>
The http://www.bkjia.com/PHPjc/718612.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/718612.htmlTechArticlecalendar.class.php code is as follows :? Php class Calendar {private $ year; // the current year private $ month; // The Current month private $ start_weekday; // The first day of the current month...