当前位置:编程学习 > php >>

PHP日历

<?php
02
SimCalendar('2011-08');
03
function SimCalendar($date)
04
{
05
    /**
06
     * 简单日历输出,本函数需要cal_days_in_month的支持
07
     * @param $date Y-m 要输出的日期
08
     */
09
    echo '<table border="1">
10
    <thead>
11
        <tr>
12
            <th>日</th>
13
            <th>一</th>
14
            <th>二</th>
15
            <th>三</th>
16
            <th>四</th>
17
            <th>五</th>
18
            <th>六</th>
19
        </tr>
20
    </thead>
21
    <tbody>';
22
        $date_array = explode('-', $date);
23
        $start_week = 0;//从星期天开始为0
24
        $month = cal_days_in_month(CAL_GREGORIAN, $date_array[1], $date_array[0]);//当月的天数
25
        $wstar = date('w', strtotime($date . '-01'));//当月从星期几天始
26
        $rows = ceil(($wstar + $month) / 7);//总行数
27
        $mday = 1;//第几天
28
        for ($i = 0; $i < $rows; $i++) {
29
            echo '<tr>';
30
            for ($d = 0; $d < 7; $d++) {
31
                $nowday = 7 * $i + $d + $start_week;
32
                if ($nowday >= $wstar && $mday <= $month) {
33
                    $temp = date('d', strtotime($date . '-' . $mday));
34
                    echo '<td>'.$temp . '</td>';
35
                    $mday++;
36
                } else {
37
                    echo '<td> </td>';
38
                }
39
            }
40
            echo '</tr>';
41
        }
42
    
43
    echo '</tbody>
44
</table>';
45
}
46
?>
作者“Flowf的博客”

补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,