PhpCalender (calendar) code sharing _ PHP Tutorial

Source: Internet
Author: User
PhpCalender (calendar) code sharing. The code is as follows :? Php ***** my calendar * date_default_timezone_setdatemktime * @ paramint $ year * @ paramint $ month * @ paramstring $ timezone * @ aut code:

The code is as follows:


/**
*
* My calendar
* Date_default_timezone_set date mktime
* @ Param int $ year
* @ Param int $ month
* @ Param string $ timezone
* @ Author fc_lamp
*/
Function myCalender ($ year = '', $ month ='', $ timezone = 'Asia/Shanghai ')
{

Date_default_timezone_set ($ timezone );
$ Year = abs (intval ($ year ));
$ Month = abs (intval ($ month ));

// Whether it is a 32-bit server
If (is32 ())
{
If ($ year <1970 or $ year> = 2038)
{
$ Year = date ('Y ');
}
} Else
{
If ($ year <= 0)
{
$ Year = date ('Y ');
}

}

If ($ month <= 0 or $ month> 12)
{
$ Month = date ('M ');
}

// Previous Year
$ PretYear = $ year-1;
// Last month
$ MpYear = $ year;
$ PreMonth = $ month-1;
If ($ preMonth <= 0)
{
$ PreMonth = 1;
$ MpYear = $ pretYear;
}

// Next year
$ NextYear = $ year + 1;
// Next month
$ MnYear = $ year;
$ NextMonth = $ month + 1;
If ($ nextMonth> 12)
{
$ NextMonth = 1;
$ MnYear = $ nextYear;
}

// Calendar header
$ Html = <















Last year Last month Back to today Next month Next year
{$ Year}-{$ month} month




































































HTML;$ CurrentDay = date ('Y-m-J ');// Last day of the month$ Lastday = date ('J', mktime (0, 0, 0, $ nextMonth, 0, $ year ));// Number of days of cyclic output$ Day = 1;$ Line = '';While ($ day <= $ lastday){$ Cday = $ year. '-'. $ month. '-'. $ day;// Current day of the week$ NowWeek = date ('N', mktime (0, 0, 0, $ month, $ day, $ year ));If ($ day = 1){$ Line =' ';$ Line. = str_repeat (' ', $ NowWeek-1 );}If ($ cday = $ currentDay){$ Style = 'style = "color: red ;"';} Else{$ Style = '';}$ Line. =" ";// End of one weekIf ($ nowWeek = 7){$ Line. =' ';$ Html. = $ line;$ Line =' ';}// End of the whole monthIf ($ day = $ lastday){If ($ nowWeek! = 7){$ Line. = str_repeat (' ', 7-$ nowWeek );}$ Line. =' ';$ Html. = $ line;Break;}$ Day ++;}$ Html. = <
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
$ Day


HTML;
Return $ html;
}

/**
*
* Check whether it is a 32-bit server.
* @ Author fc_lamp
* @ Blog: fc-lamp.blog.163.com
*/
Function is32 ()
{
$ Is32 = False;
If (strtotime ('2017-10-10 ') = False)
{
$ Is32 = True;
}
Return $ is32;
}

The pipeline code is as follows :? Php/*** my calendar * date_default_timezone_set date mktime * @ param int $ year * @ param int $ month * @ param string $ timezone * @ aut...

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.