日历

<?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>';//结束
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值