Php calendar [tested]

Source: Internet
Author: User
I have always liked the calendar implementation code in php. a php calendar code with good test results

The code is as follows:


/**
* Calendar
*
* Copyright (c) 2007 by Chen Yixin (Deep Space). All rights reserved
* To contact the author write to {@ link mailto: shenkong@php.net}
* @ Author Chen Yixin (Deep Space)
*/
If (function_exists ('date _ default_timezone_set ')){
Date_default_timezone_set ('Asia/Chongqing ');
}
$ Date = isset ($ _ GET ['Date'])? $ _ GET ['Date']: date ('Y-m-D ');
$ Date = getdate (strtotime ($ date ));
$ End = getdate (mktime (0, 0, 0, $ date ['mon'] + 1, 1, $ date ['Year'])-1 );
$ Start = getdate (mktime (0, 0, 0, $ date ['mon'], 1, $ date ['Year']);
$ Pre = date ('Y-m-D', $ start [0]-1 );
$ Next = date ('Y-m-D', $ end [0] + 86400 );
$ Html ='


































';$ Html. =' ';$ Html. =' ';$ Html. =' ';$ Html. =' ';$ Html. =' ';$ Arr_tpl = array (0 => '', 1 =>'', 2 => '', 3 =>'', 4 => '', 5 => '', 6 => '');$ Date_arr = array ();$ J = 0;For ($ I = 0; $ I <$ end ['mday']; $ I ++ ){If (! Isset ($ date_arr [$ j]) {$ Date_arr [$ j] = $ arr_tpl;}$ Date_arr [$ j] [($ I + $ start ['wday']) % 7] = $ I + 1;If ($ date_arr [$ j] [6]) {$ J ++;}}Foreach ($ date_arr as $ value ){$ Html. =' ';Foreach ($ value as $ v ){If ($ v ){If ($ v = $ date ['mday']) {$ Html. =' ';} Else {$ Html. =' ';}} Else {$ Html. =' ';}}$ Html. =' ';}$ Html. ='
-'. $ Date ['Year'].'; '. $ date ['month'].'+
'. $ V .''. $ V .'
';
Echo $ html;
?>


Php calendar code 2

The code is as follows:


/**
* Calendar
*/
If (function_exists ('date _ default_timezone_set ')){
Date_default_timezone_set ('Asia/Chongqing ');
}
$ Date = isset ($ _ GET ['Date'])? $ _ GET ['Date']: date ('Y-m-D ');
$ Date = getdate (strtotime ($ date ));
$ End = getdate (mktime (0, 0, 0, $ date ['mon'] + 1, 1, $ date ['Year'])-1 );
$ Start = getdate (mktime (0, 0, 0, $ date ['mon'], 1, $ date ['Year']);
$ Pre = date ('Y-m-D', $ start [0]-1 );
$ Next = date ('Y-m-D', $ end [0] + 86400 );
$ Html ='



































Align = "center" style = "line-height: 150%; font-family: Verdana,; font-size: 12px;"> ';$ Html. =' ';$ Html. =' ';$ Html. =' ';$ Html. =' ';$ Html. =' ';$ Arr_tpl = array (0 => '', 1 =>'', 2 => '', 3 =>'', 4 => '', 5 => '', 6 => '');$ Date_arr = array ();$ J = 0;For ($ I = 0; $ I <$ end ['mday']; $ I ++ ){If (! Isset ($ date_arr [$ j]) {$ Date_arr [$ j] = $ arr_tpl;}$ Date_arr [$ j] [($ I + $ start ['wday']) % 7] = $ I + 1;If ($ date_arr [$ j] [6]) {$ J ++;}}Foreach ($ date_arr as $ value ){$ Html. =' ';Foreach ($ value as $ v ){If ($ v ){If ($ v = $ date ['mday']) {$ Html. =' ';} Else {$ Html. =' ';}} Else {$ Html. =' ';}}$ Html. =' ';}$ Html. ='
-'. $ Date ['Year'].'; '. $ date ['month'].'+
'. $ V .''. $ V .'
';
Echo $ html;
?> Bytes


The following is a good example. the system prompts errors and provides clear ideas.

The code is as follows:


Function calendar ()
{
If ($ _ GET ['ym'])
{
$ Year = substr ($ _ GET ['ym );
$ Month = substr ($ _ GET ['ym'], 4, (strlen ($ _ GET ['ym'])-4 ));

If ($ month> 12)
{
$ Year + = floor ($ month/12 );
$ Month = $ month % 12;
}
If ($ year> 2030) $ year = 2030;
If ($ year <1980) $ year = 1980;
}

$ Year = isset ($ year )? $ Year: date ('Y ');
$ Month = isset ($ month )? $ Month: date ('N ');

If ($ year = date ('Y') & $ month = date ('N') $ today = date ('J ');

If ($ month-1 = 0)
$ Prevmonth = ($ year-1). "12 ";
Else $ prevmonth = $ year. ($ month-1 );

If ($ month + 1 = 13)
$ Nextmonth = ($ year + 1). "1 ";
Else $ nextmonth = $ year. ($ month + 1 );

$ Prevyear = ($ year-1). $ month;
$ Nextyear = ($ year + 1). $ month;

Echo <




















































VKN;$ Nowtime = mktime (0, 0, 0, $ month, 1, $ year); // convert the value 1 to the second of the current month$ Daysofmonth = date (t, $ nowtime); // Number of days in the current month$ Weekofbeginday = date (w, $ nowtime); // The Day of the week on the first day of the month$ Weekofendday = date (w, mktime (, 0, 0, $ month +, $ year); // The last day of the month is the day of the week.$ Daysofprevmonth = date (t, mktime (, 0, $ month, 0, $ year); // Number of days in the previous month$ Count = 1; // count// List the days after the previous monthFor ($ I = 1; $ I <= $ weekofbeginday; $ I ++){Echo" ";$ Count ++;}// All for the current monthFor ($ I = 1; $ I <= $ daysofmonth; $ I ++){$ Css = ($ count % 7 = 0 | $ count % 7 = 1 )? "Weekday": "normalday ";If ($ I = $ today) $ css. = "today ";Echo" ";If ($ count % 7 = 0) echo" ";$ Count ++;}// A few days before next monthFor ($ I = 1; $ I <= 6-$ weekofendday; $ I ++){Echo" ";}Echo <
< < $ Year-$ month > >
Day I II 3. Thu V. Sat.
". ($ Daysofprevmonth-$ weekofbeginday + $ I )."". $ I ."
". $ I ."

VKN;
}
?>




Calendar






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.