日历

来源:互联网 发布:origin作图软件中文版 编辑:程序博客网 时间:2024/06/18 17:00
<?php//年份$year = isset($_GET['year']) ? $_GET['year'] : date('y');//当前月份$month = isset($_GET['month'])? $_GET['month'] : date('m');//当前的日$day = isset($_GET['day']) ? $_GET['day'] : date('d');//获取当月的天数$days = date('t', mktime(0,0,0, $month, 1, $year));//获取当月的1号是星期几$startweek  = date('w', mktime(0,0,0, $month, 1, $year));echo "当天是{$year}年{$month}月{$day}日,这个月的1号是星期{$startweek}<br>";//http://localhost/network2/week12/date5.php?year=2017&month=5&day=2//创建表格echo '<table border="0px" width="500px" align="center">';//创建表头echo '<tr>';echo '<th style="background-color: darkgrey">星期日</th>';echo '<th style="background-color: darkgrey">星期一</th>';echo '<th style="background-color: darkgrey">星期二</th>';echo '<th style="background-color: darkgrey">星期三</th>';echo '<th style="background-color: darkgrey">星期四</th>';echo '<th style="background-color: darkgrey">星期五</th>';echo '<th style="background-color: darkgrey">星期六</th>';echo  '</tr>';//通过循环来实现日历内容echo '<tr>';//输出空白 1号前面的空白for($i = 0; $i<$startweek; $i++){    echo '<td>&nbsp;</td>';}for($j = 1; $j <= $days; $j++){    echo "<td align='center' >{$j}</td>";    $i++;    //换行    if($i % 7 ==0){       echo '</tr><tr>';    }}//作业: 日历//尾处的留白while($i%7 !== 0){    echo '<td>&nbsp;</td>';    $i++;}echo '</tr>';echo '</table>';//结束?>