<?php//修改頁面編碼header("content-type:text/html;charset=utf-8");//獲取當前年$year=$_GET['y']?$_GET['y']:date('Y');//獲取當年月$month=$_GET['m']?$_GET['m']:date('m');//獲取當前月多少天$days=date('t',strtotime("{$year}-{$month}-1"));//當前一號周幾$week=date('w',strtotime("{$year}-{$month}-1"));//居中echo "<center>";//計算上個月if($month==1){ $prevyear=$year-1; $prevmonth=12;}else{ $prevyear=$year; $prevmonth=$month-1;}//計算下個月if($month==12){ $nextyear=$year+1; $nextmonth=1;}else{ $nextyear=$year; $nextmonth=$month+1;}//輸出表頭echo " <h2><a href='萬年歷.php?y={$prevyear}&m={$prevmonth}'>上一月</a>|{$year}年{$month}月|<a href='萬年歷.php?y={$nextyear}&m={$nextmonth}'>下一月</a></h2>";//輸出日期表格echo "<table width='700px' border='1px'>";echo "<tr>";echo "<th>周日</th>";echo "<th>周一</th>";echo "<th>周二</th>";echo "<th>周三</th>";echo "<th>周四</th>";echo "<th>周五</th>";echo "<th>周六</th>";echo "</tr>";//鋪表格for ($i=1-$week; $i <=$days ;) { echo "<tr>"; for ($j=0; $j < 7; $j++) { if ($i>$days || $i<1) { echo "<td> </td>"; } else { echo "<td>{$i}</td>"; } $i++; } echo "</tr>"; }echo "</table>";echo "</center>";?>
相關推薦:
PHP中抽象方法以及抽象類與接口的簡單介紹
PHP想要實現頁面跳轉功能具體怎么操作?(函數標簽示例)
LNMP以源碼實現環境搭建的過程(詳細)
以上就是php實現萬年歷的完整代碼的詳細內容,更多請關注 其它相關文章!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答