標籤:amp idt http 製作 while 迴圈 多少 ref array
<?php/** * 1.擷取日期年和月,預設當前年份和月份 * 2.計算當前月份有多少天和本月1號是星期幾 * 3.輸出日期的頭部資訊 * 4.迴圈遍曆輸出輸出天數 * 5.完成上一月和下一月連結 * **///1.$year = empty($_REQUEST[‘y‘]) ? date("Y") : intval($_REQUEST[‘y‘]);$month = empty($_REQUEST[‘m‘]) ? date("m") : intval($_REQUEST[‘m‘]);//2.$day = date("t",mktime(0,0,0,$month,‘1‘,$year));//擷取對應該月的天數$moneday = date("w",mktime(0,0,0,$month,‘1‘,$year)); //擷取該月的星期幾//3.$weekarr = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); echo "<center>";echo "<h1>{$year}年{$month}月</h1>";echo "<table width=‘600‘ border=‘1‘ >";echo "<tr>";for($i=0;$i<=6;$i++){ echo "<th>{$weekarr[$i]}</th>";}echo "</tr>";echo "<tr>";//4.$ed = 1;while($ed <= $day){ //每七天換行 echo "<tr>"; for($i=0;$i<=6;$i++){ //不能超過當月的天數且還沒有該輸出日期的時候 if($ed <= $day && ($moneday <= $i || $ed != 1) ){ echo "<td>{$ed}</td>"; $ed++; }else{ echo "<td></td>"; } } }echo "</tr>";echo "</table>";//5$prey = $nexty = $year;//年$prem = $nextm = $month;//月if($prem <= 1){ $prem = 12; $prey--;}else{ $prem--;//上一月}if($nextm >= 12){ $nextm = 1; $nexty++;}else{ $nextm++;//下一月}echo "<h3><a href=‘wanianli.php?y={$prey}&m={$prem}‘>上一月</a> ";echo "<a href=‘wanianli.php?y={$nexty}&m={$nextm}‘>下一月</a></h3>";echo "</center>";
製作一個php萬年曆