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. = '
' . $date [' Year ']. ';' . $date [' Month ']. ' | '; $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. = ')
' . $v. ' | '; } else {$html. = '
' . $v. ' | '; }} else {$html. = '
| '; }} $html. = '
'; } $html. = '
';
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. = '
' . $date [' Year ']. ';' . $date [' Month ']. ' | '; $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. = ')
' . $v. ' | '; } else {$html. = '
' . $v. ' | '; }} else {$html. = '
| '; }} $html. = '
'; } $html. = '
';
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 <<
<< |
< |
$year-$month |
> |
>> |
Day |
One |
Two |
Three |
Four |
Five |
Six |
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 "
". ($daysofprevmonth-$weekofbeginday + $i). " | "; $count + +; }//month all for ($i = 1; $i <= $daysofmonth; $i + +) {$css = ($count%7==0 | | $count%7==1)? " Weekday ":" Normalday "; if ($i = = $today) $css. = "Today"; echo "
". $i." | "; if ($count%7==0) echo "
"; $count + +; }//A few days before next month for ($i = 1; $i <= 6-$weekofendday; $i + +) {echo "
". $i." | "; } Echo <<
|
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 {@ ...