PHP complete calendar CLASS _ php instance

Source: Internet
Author: User
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 "; // Supplemental PrintingFor ($ tnmpc = 0; $ tnmpc <$ fweek; $ Tmpc ++ ){Echo"
". $ 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"
";
}
}
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 ();
?>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.