用php編寫的日曆

來源:互聯網
上載者:User
網上有很多JavaScript編寫的日曆,這種日曆讀取的是本地的時間,可能會不準確。所以想找一個用php編寫的,能讀取伺服器時間的日曆,但是一直都找不到合適的,於是我自己嘗試著寫了一個。
代碼
<?php
$mnow=(isset($HTTP_GET_VARS['month']) && intval($HTTP_GET_VARS['month'])>0 && intval($HTTP_GET_VARS['month'])<13)?intval($HTTP_GET_VARS['month']):date("m");
$ynow=(isset($HTTP_GET_VARS['year']) && intval($HTTP_GET_VARS['year'])>1969 && intval($HTTP_GET_VARS['year'])<2038)?intval($HTTP_GET_VARS['year']):date("Y");
$mtime=mktime(0,0,0,$mnow,date("d"),$ynow);
$f=date("w",mktime(0,0,0,$mnow,1,$ynow))-1;
echo "<table id="calendar" border="0" cellpadding="2" cellspacing="1">";
echo "<tr><td colspan="4" align="center" class="calendartitle"><a href="?".($mnow!=date("m")?"month=".intval($mnow)."&":"")."year=".(intval($ynow)==1970?"1970":intval($ynow)-1)."">&lt;</a>".$ynow."<a href="?".($mnow!=date("m")?"month=".intval($mnow)."&":"")."year=".(intval($ynow)==2037?"2037":intval($ynow)+1)."">&gt;</a></td><td colspan="3" align="center" class="calendartitle"><a href="?month=".(intval($mnow)==1?"12":intval($mnow)-1).($ynow!=date("Y")?"&year=".intval($ynow):"")."">&lt;</a>".date("M",$mtime)."<a href="?month=".(intval($mnow)==12?"1":intval($mnow)+1).($ynow!=date("Y")?"&year=".intval($ynow):"")."">&gt;</a></td></tr>";
echo "<tr><td class="calendartop">S</td><td class="calendartop">M</td><td class="calendartop">T</td><td class="calendartop">W</td><td class="calendartop">T</td><td class="calendartop">F</td><td class="calendartop">S</td></tr>";
for($i=0;$i<date("t",$mtime)+$f+1;$i++){
if($i%7==0)echo "<tr>";
echo "<td".(($i-$f==intval(date("d")) && $mnow==date("m") && $ynow==date("Y"))?" id="calendartoday"":"").(($i%7==0 || $i%7==6)?" class="calendarw"":"").">";
if($i>$f)echo $i-$f;
echo "</td>";
if($i%7==6)echo "</tr>";
}
if($i%7<6 && $i%7>0)echo "<td colspan="".(7-$i%7).""></td></tr>";
if($i%7==6)echo "<td></td></tr>";
echo "</table>";
?>

聯繫我們

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