PHP complete calendar CLASS)
The Code is as follows:
Class Calendar {
/*
* Www.php.net revised version
*/
Var $ YEAR, $ MONTH, $ DAY;
Var $ WEEK = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");
Var $ _ MONTH = array (
"01" => "August January ",
"02" => "August February ",
"03" => "August March ",
"04" => "August April ",
"05" => "August May ",
"06" => "August June ",
"07" => "August July ",
"08" => "August ",
"09" => "August September ",
"10" => "August October ",
"11" => "August November ",
"12" => "August December"
);
// Set the year
Function setYear ($ year ){
$ This-> YEAR = $ year;
}
// Obtain the year
Function getYear (){
Return $ this-> YEAR;
}
// Set the month
Function setMonth ($ month ){
$ This-> MONTH = $ month;
}
// Obtain the month
Function getMonth (){
Return $ this-> MONTH;
}
// Set the date
Function setDay ($ day ){
$ This-> DAY = $ day;
}
// Obtain the date
Function getDay (){
Return $ this-> DAY;
}
// Print the calendar
Function OUT (){
$ This-> _ env ();
$ Week = $ this-> getWeek ($ this-> YEAR, $ this-> MONTH, $ this-> DAY ); // obtain the day of the week (for example, today is, Friday)
$ Fweek = $ this-> getWeek ($ this-> YEAR, $ this-> MONTH, 1); // obtain the day of the week on the first day of the MONTH.
Echo"
WEEK); $ Tmpa ++) {// print the weekly Header
Echo"
";For ($ Tmpa = 0; $ Tmpa
". $ This-> WEEK [$ Tmpa]; } For ($ Tmpb = 1; $ Tmpb <= date ("t", mktime (0, 0, $ this-> MONTH, $ this-> DAY, $ this-> YEAR); $ Tmpb ++) {// print all dates If (strcmp ($ Tmpb, $ this-> DAY) = 0) {// obtain the current date and mark it $ Flag = "bgcolor = '# ff0000 '"; } Else { $ Flag = 'bgcolor = # ffff '; } If ($ Tmpb = 1 ){ Echo" |
"; // Supplemental PrintingFor ($ tnmpc = 0; $ tnmpc <$ fweek; $ Tmpc ++ ){Echo"
"; } } If (strcmp ($ this-> getWeek ($ this-> YEAR, $ this-> MONTH, $ Tmpb), 0) = 0 ){ Echo" |
$ Tmpb "; } Else { Echo" |
$ Tmpb "; } } Echo" |
";
}
// Obtain the number of weeks of the specified date in the method.
Function getWeek ($ year, $ month, $ day ){
$ Week = date ("w", mktime (0, 0, 0, $ month, $ day, $ year); // obtain the week
Return $ week; // obtain the week
}
Function _ env (){
If (isset ($ _ POST ["month"]) {// has a specified month
$ Month = $ _ POST ["month"];
} Else {
$ Month = date ("m"); // The default value is this month.
}
If (isset ($ _ POST ["year"]) {// year
$ Year = $ _ POST ["year"];
} Else {
$ Year = date ("Y"); // The default value is this year.
}
$ This-> setYear ($ year );
$ This-> setMonth ($ month );
$ This-> setDay (date ("d "));
}
}
$ D = new Calendar;
$ D-> OUT ();
?>