·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> php基础练习--简易万年历

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

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
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

通过这个基础练习,主要是为了掌握for循环的运用,判断tr和td标签的位置来掌握for循环嵌套的使用。