日历页面展示

1,mktime()函数的使用,获取当前月的天数及当月1号的星期(2018/3/13)

<?php
$day=date("t",mktime(0,0,0,$mon,1,$year));//当前月的天数  31
$w=date("w",mktime(0,0,0,$mon,1,$year));//当月1号的星期几  4

2,输出日历的头部信息

<?php
echo"<div align='center'>";
echo"<table border='0'>";
echo"<h3><div>{$year}年{$mon}月</div></h3>";
echo "<tr>";
echo "<th>日</th>";
echo "<th class='td1'>一</th>";
echo "<th class='td1'>二</th>";
echo "<th class='td1'>三</th>";
echo "<th class='td1'>四</th>";
echo "<th class='td1'>五</th>";
echo "<th>六</th>";
echo "</tr>";

3,遍历输出日历

分析:

由mktime()函数可知 当前月总共天数,当月1号是星期几,只需要在小于当月总天数时每次进行7天的遍历输出,

从当月1号对应的星期几开始每天加1,循环一次7天就是一行数据,这样日历就出来了

代码:

<?php
$d=1;
while($d<=$day){
    echo"<tr onmouseOver='overTr(this)'onmouseOut='outTr(this)'>";
    for($i=1;$i<=7;$i++){//循环输出7天信息
        if($d<=$day&&($w<$i||$d!=1)){
            echo "<th><a href=''>{$d}</a></th>";
            $d++;
        }else{
            echo"<th> </th>";
        }
    }
}

运行结果如下:

微信图片_20180313153005.png

继续学习
||
<?php echo "日历的基本显示";
提交重置代码
章节
笔记
提问
课件
反馈
捐赠

PHP制作阴阳历转换的日历插件

高并发千万级数据库系统解决方案
  • 推荐课程
  • 评论
  • 问答
  • 笔记
  • 课件下载

<?php $mon= date('m'); $year=date('Y'); $day=date("t",mktime(0,0,0,$mon,12,$year));//当前月的天数 31 $w=date("w",mktime(0,0,0,$mon,1,$year));//当月1号的星期几 4 echo"<div align='c

4年前    添加回复 0

沉默技术博客

我觉得那你那里("w",mktime(0,0,0,$mon,1,$year));的w应该写成d,是从本月开始的星期开始的吧$begin_day=date("d",mktime(0,0,0,$month,$day,$year));

5年前    添加回复 0

沉默技术博客

我表示弄不懂

5年前    添加回复 0

麻辣爱上酸汤

使用hbuilder可以实现的吧

5年前    添加回复 0

代码出错?

[最新 johnxu 的回答] 表示完全读不懂问题_-_

时间:5年前

课件暂不提供下载,工作人员正在整理中,后期请多关注该课程~