製作一個php萬年曆

來源:互聯網
上載者:User

標籤: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>&nbsp;&nbsp;";echo "<a href=‘wanianli.php?y={$nexty}&m={$nextm}‘>下一月</a></h3>";echo "</center>";

 

 

製作一個php萬年曆

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.