PHP Calendar [Test via]_php Tutorial

Source: Internet
Author: User
A very good PHP calendar code
Copy CodeThe code is as follows:
/**
* Calendar
*
* Copyright (c) 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 + $sta rt[' 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
Copy CodeThe 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, song body; 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 + $sta rt[' 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;
?>

The following is also good, suggesting that there are errors, clear thinking
Copy CodeThe code is as follows:
function Calendar ()
{
if ($_get[' ym ')
{
$year = substr ($_get[' ym '],0,4);
$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);//1th to seconds of the month$daysofmonth = Date (t, $nowtime);//Days of the Month$weekofbeginday = Date (w, $nowtime);//The first day of the month is the days of the week$weekofendday = Date (W,mktime (0,0,0, $month +1,0, $year));//The Last day of the month is the days of the week$daysofprevmonth = Date (T,mktime (0,0,0, $month, 0, $year));//number of days last month$count = 1;//CountList the days after last monthfor ($i = 1; $i <= $weekofbeginday; $i + +){echo " "; $count + +; }//month all for ($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 month for ($i = 1; $i <= 6-$weekofendday; $i + +) {echo " "; } Echo <<
<< < $year-$month > >>
Day One Two Three Four Five Six
". ($daysofprevmonth-$weekofbeginday + $i). "". $i."
". $i."

VKN;
}
?>




<title>Calendar</title>







http://www.bkjia.com/PHPjc/318769.html www.bkjia.com true http://www.bkjia.com/PHPjc/318769.html techarticle a very good PHP calendar code copy code is as follows:? PHP/** * Calendar * * Copyright (c) by Chen Yixin (Deep Space). All rights reserved * To contact the author write to {@ ...

  • 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.