Ec (2); & lt ;? PhpclassCalendar {& nbsp; ** & nbsp; * @ desc & nbsp;: simple calendar class for everyone to learn & nbsp; * @ author & nbsp;: AllenWu & nbsp; script ec (2); script
Class Calendar {
/**
* @ Desc: simple calendar class for everyone to learn
* @ Author: Allen Wu
* @ Email: wukewei00o@126.com
* @ Date: 2008-09-12
* @ Version: v1.0
*/
/* Define the variable year, month, and day */
Private $ year, $ month, $ day;
/* Define the array week and initialize */
Private $ week = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");
/* Define the array month and initialize */
Private $ monthes = 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"
);
Function _ construct (){
$ Year = isset ($ _ POST ['Year'])? $ _ POST ['Year']: date ('y ');
$ Month = isset ($ _ POST ['month'])? $ _ POST ['month']: date ('M ');
$ Day = isset ($ _ POST ['day'])? $ _ POST ['day']: date ('D ');
$ This-> set ($ year, $ month, $ day );
}
/**
* @ Desc set the values of year, month, and day
* @ Params String $ year
* @ Params String $ month
* @ Params String $ day
* @ Return
*/
Private function set ($ year, $ month, $ day ){
$ This-> year = $ year;
$ This-> month = $ month;
$ This-> day = $ day;
}
/**
* @ Desc get the value of year, month, and day and return it as an array
* @ Params Array $ info
* @ Retrun Array
*/
Function get (array $ info ){
$ Info = array ('Year' => $ this-> year,
'Month' => $ this-> month,
'Day' => $ this-> day );
Return $ info;
}
/**
* @ Desc get the week value of the specified date
* @ Params String $ year
* @ Params String $ month
* @ Params String $ day
* @ Return String
*/
Private function getWeek ($ year, $ month, $ day ){
$ Weekday = date ("w", mktime (0, 0, 0, $ month, $ day, $ year ));
Return $ weekday;
}
/**
* Output calendar. If you are interested, you can improve it!
* In fact, this is not a method. You do not want html and styles to appear in the class.
* If you are interested, you can improve it! I will give you an interesting role.
*
*/
Public function out (){
$ FirstDay = $ this-> getWeek ($ this-> year, $ this-> month, 1 );
Echo"
".
"
";/* Print the weekly header */For ($ week = 0; $ week <count ($ this-> week); $ week ++ ){Echo"
". $ This-> week [$ week];
}
/* Print all dates */
For ($ tmpd = 1; $ tmpd <= date ("t", mktime (0, 0, $ this-> month, $ this-> day, $ this-> year); $ tmpd ++ ){
If (strcmp ($ tmpd, $ this-> day) = 0) {// obtain the current date and mark it
$ Flag = "bgcolor = '# ff0000 '";
} Else {
$ Flag = "bgcolor = '# ffff '";
}
If ($ tmpd = 1 ){
Echo" |
"; // Supplemental PrintingFor ($ I = 0; $ I <$ firstDay; $ I ++ ){Echo"
";
}
}
If (strcmp ($ this-> getWeek ($ this-> year, $ this-> month, $ tmpd), 0) = 0 ){
Echo" |
$ Tmpd ";
} Else {
Echo" |
$ Tmpd ";
}
}
Echo" |
";
}
}
$ Obj = new Calendar ();
$ Obj-> out ();
?>