php

使用php编写一个年历程序

Jason
2020-10-02 / 0 评论 / 443 阅读 / 正在检测是否收录...
<?php
    echo "<style type='text/css'>
            th{
                background-color: gray;
                
            }
            table{
                padding:10px 30px 10px 10px;
                border:0px;
                display: inline-flex;
            }
            td{
                width:40px;
            }
            *{
                margin: 2px;
                padding: 2px;
            }
        </style>";
    $y = 2017;
    $w = date('w',strtotime("$y-1-1"));
    for($m=1;$m<=12;$m++){
        echo "<table>";
        echo "<tr><th colspan='7'>{$y}年{$m}月</th></tr>";
        echo "<tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>";
        $lastday = date('d', strtotime("{$y}-$m-01 +1 month -1 day"));
        for($day=1;$day<=$lastday;$day++){
            if($w==7){
                echo  "</tr>";
                $w=0;
            }elseif($w==0){
                echo  "<tr>";
            }
            $s = date('w',strtotime("$y-$m-1"));
            if($day == 1){
                for($weeks=1;$weeks<=$s;$weeks++){
                    echo "<td></td>";
                }
            }
            echo "<td>{$day}</td>";
            $w++;
        }
        echo "</table>";
    
0

评论 (0)

取消