PHP學習筆記之萬年曆錶

來源:互聯網
上載者:User
PHP學習筆記之月曆表




月曆表
$MONTH = array("元月","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
$enMONTH = array("元月","January" ,"February" ,"Marcy" ,"April" ,"May" ,"June" ,"July" ,"August" ,"September" ,"October" ,"November" ,"December");
$WEEK = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
$BACKCOLOR = array("#FFC" , "#FFF" , "#9F6" , "#FFC" , "#6F0" , "#6F6" , "#F90" , "#F06" , "#F00" , "#FC3" , "#FF6" , "#F99");

function PrintMon($year, $mon)
{
date_default_timezone_set("Asia/Shanghai");
global $MONTH;
global $enMONTH;
global $WEEK;
global $BACKCOLOR;

$startdate =strtotime("1 $enMONTH[$mon] $year"); //擷取查詢的年月
$enddate = strtotime("+1 month",$startdate); //擷取下一個月的開始日期作為月曆輸出的截止時間
$theDate = getdate($startdate); //把日期轉化為字串格式
$color = $BACKCOLOR[$mon]; //設定月曆的背景顏色

echo("





























































  • "); $ym = $year . "年". $MONTH[$mon]; echo(" "); echo(" "); for ($i=0; $i<7; $i++) //輸出星期幾 { echo(" "); } echo(" "); $theWeek = $theDate[wday];//判斷當天是星期幾 for ($i=0; $i<6; $i++) { echo(" "); for ($j=0; $j<7; $j++) { echo(" "); } echo(" "); if ($startdate == $enddate) //如果已經輸出全部日期,結束迴圈 { $i = 6; } } echo(" } ?> $year = $_POST['myYear']; $month = $_POST['myMonth']; if (is_numeric($year) && $year >= 1970 && $year <2038) { if (is_numeric($month) && $month >= 1 && $month <=12) { PrintMon($year, $month); } else if($month != NULL) { echo("月份不對" . ""); } } else if($year != NULL) { echo("年份不對" . ""); }?>

    $ym

    ");
    echo("

    $WEEK[$i]

    ");
    echo("
    ");
    if ($startdate < $enddate && $theWeek == $j)//把日期輸出到對應的星期幾所在列,並注意不要超出本月日期
    {
    $theDay = $theDate[mday];
    echo("

    $theDay

    ");
    $startdate = strtotime("+1 day", $startdate); //日期前移1天
    $theDate = getdate($startdate);//更新日期
    $theWeek = ($theWeek + 1) % 7;//更新星期
    }
    echo("

    聯繫我們

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