php日曆[測試通過]_PHP教程

來源:互聯網
上載者:User
比較不錯的一款php日曆代碼
複製代碼 代碼如下:
/**
* 日曆
*
* Copyright(c) 2007 by 陳毅鑫(深空). All rights reserved
* To contact the author write to {@link mailto:shenkong@php.net}
* @author 陳毅鑫(深空)
*/
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日曆代碼2
複製代碼 代碼如下:
/**
* 日曆
*/
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;
?>

下面這個也不錯,提示有錯誤,思路清晰
複製代碼 代碼如下:
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);//當月1號轉為秒 $daysofmonth = date(t,$nowtime);//當月天數 $weekofbeginday = date(w,$nowtime);//當月第一天是星期幾 $weekofendday = date(w,mktime(0,0,0,$month+1,0,$year));//當月最後一天是星期幾 $daysofprevmonth = date(t,mktime(0,0,0,$month,0,$year));//上個月天數 $count = 1;//計數 //列出上月後幾天 for($i = 1 ; $i <= $weekofbeginday ; $i++) { echo " "; $count++; } //當月全部 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++; } //下月前幾天 for ($i = 1;$i <= 6-$weekofendday;$i++) { echo " "; } echo <<
<< < $year - $month > >>
".($daysofprevmonth-$weekofbeginday+$i)."".$i."
".$i."

VKN;
}
?>




calendar







http://www.bkjia.com/PHPjc/318769.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318769.htmlTechArticle比較不錯的一款php日曆代碼 複製代碼 代碼如下: ?php /** * 日曆 * * Copyright(c) 2007 by 陳毅鑫(深空). All rights reserved * To contact the author write to {@...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.