php基础练习--简易万年历

php简易万年历:

<?php
    /**
    *  calendar
    */

    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"));
    $weeks = date("w", strtotime("{$year}-{$month}-1"));

    echo "<center>";
    echo "<h2>{$year}-{$month}</h2>";
    echo "<table width=‘700px‘ border=‘1px‘ cellpadding=‘3‘ cellspacing=‘0‘>";
    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 - $weeks; $i <= $days;) {
        echo "<tr>";
        for ($j=0; $j <7 ; $j++) { 
            if ($i > $days || $i <= 0) {
                echo "<td>&nbsp;</td>";
            } else {
                echo "<td>{$i}</td>";
            }
            $i++;
        }
        echo "</tr>";
    }

    echo "</table>";
    if ($month == 1) {
        $prevmonth = 12;
        $prevyear = $year - 1;
    } else {
        $prevmonth = $month - 1;
        $prevyear = $year;
    }

    if ($month == 12) {
        $nextmonth = 1;
        $nextyear =$year +1;
    } else {
        $nextmonth = $month +1;
        $nextyear = $year;
    }



    echo "<h3><a href=‘index.php?y={$prevyear}&m={$prevmonth}‘>上一月</a>|
        <a href=‘index.php?y={$nextyear}&m={$nextmonth}‘>下一月</a></h3>";
    echo "</center>";
calendar

我是一只php小菜鸟,正在努力长大。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。