PHP之日历

来源:互联网 发布:mysql 存储过程 参数 编辑:程序博客网 时间:2024/05/01 01:24
<?php/** * Created by PhpStorm. * User: zzu * Date: 13-5-8 * Time: 下午3:05 *///日历////echo $_GET['year'];$year=isset($_GET['year'])?$_GET['year']:date('y');//获取月份$month=isset($_GET['month'])?$_GET['month']:date('m');//天数$day=isset($_GET['$day'])?$_GET['$day']:date('d');echo "{$year}年{$month}月{$day}日";echo '<hr>';//1、获取当月的1号在星期几$startweek=date('w',mktime(0,0,0,$month,1,$year));//2、获取当月有多少天  t:月份有多少天$days=date('t',mktime(0,0,0,$month,$year));echo "{$year}年{$month}月{$day}日 1号是星期{$startweek} 这个月有{$days}天";//创建一个表格echo '<table border="1px" width="450px" align="center"';echo '<tr>';//行echo '<th style="background-color: #9A0000">星期日</th>';echo '<th style="background-color: #9A0000">星期一</th>';echo '<th style="background-color: #9A0000">星期二</th>';echo '<th style="background-color: #9A0000">星期三</th>';echo '<th style="background-color: #9A0000">星期四</th>';echo '<th style="background-color: #9A0000">星期五</th>';echo '<th style="background-color: #9A0000">星期六</th>';echo '</tr>';//头部空白echo  '<tr>';for($i=0;$i<$startweek;$i++){    echo  '<td>&nbsp</td>';}//1——31号之间for($j=1;$j<=$days;$j++){    $i++;    echo "<td align='center'>{$j}</td>";    if($i%7==0){        echo '</tr><tr>';    }}//尾部的空白while($i%7!==0){    echo '<td>&nbsp</td>';    $i++;}echo  '</tr>';echo  '</table>';