Php simple calendar Program-PHP source code

Source: Internet
Author: User
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" "; // Supplemental PrintingFor ($ I = 0; $ I <$ firstDay; $ I ++ ){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"
";
}
}
If (strcmp ($ this-> getWeek ($ this-> year, $ this-> month, $ tmpd), 0) = 0 ){
Echo"
$ Tmpd ";
} Else {
Echo"
$ Tmpd ";
}
}
Echo"

";
}
}
$ Obj = new Calendar ();
$ Obj-> out ();
?>

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.