PHP中怎么编写日历表?达成一个简单日历的实例
发布时间:2022-04-18 14:01:45 所属栏目:语言 来源:互联网
导读:PHP中怎么编写日历表?日历表能够清楚的展示年月日信息,那么我们如何用PHP来实现呢?下面是实现一个简单日历表的代码,感兴趣的朋友可以看一看。 calendar.class.php ?php /* * 创建一个日历类 * * */ //修改默认时区 date_default_timezone_set(PRC); clas
![]() PHP中怎么编写日历表?日历表能够清楚的展示年月日信息,那么我们如何用PHP来实现呢?下面是实现一个简单日历表的代码,感兴趣的朋友可以看一看。 calendar.class.php <?php /* * 创建一个日历类 * * */ //修改默认时区 date_default_timezone_set("PRC"); class Calendar { private $year; private $month; private $day; //当月总天数 private $first_week; //每月的第一天是星期几 //构造函数 function __construct() { $this->year = isset($_GET['year'])?$_GET['year']:date("Y"); $this->month = isset($_GET["month"])?$_GET["month"]:date("m"); $this->first_week = date("w", mktime(0, 0 ,0, $this->month, 1, $this->year)); $this->day = date("t", mktime(0, 0 ,0, $this->month, 1, $this->year)); } function showCalendar() { // echo $this->year."年".$this->month."月".$this->first_week."天".$this->day; echo "<table align='center'>"; //用表格输出 $this->chageDate("index.php"); //用于用户调整年月份 $this->weekList();//显示星期 $this->dayList(); //显示天数 //2.显示天数 private function dayList() { $color = "#2ca50c"; echo "<tr>"; for ($i = 0; $i < $this->first_week; $i++) { //输出空格,弥补当前月空缺部分 echo "<td bgcolor='#2ca50c'> </td>"; } for ($k = 1; $i <= $this->day; $k++) { $i++; if ($k == date("d")) echo "<td id='nowd'>".$k."</td>"; //是今天,加效果 else echo "<td bgcolor=$color>".$k."</td>"; if ($i % 7 == 0) { echo "</tr><tr>"; //每7天一次换行 if ($i % 2 == 0) $color = "#2ca50c"; else $color = "#9ddb27"; //实现各行换色的效果 (编辑:云计算网_泰州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |