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 |
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |
Sunday |
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. ="
$ Day | ";// 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. = <
|
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...