首页 > 编程 > PHP > 正文

PHP实现的简单日历类

2020-03-22 16:42:41
字体:
来源:转载
供稿:网友
本文实例讲述了PHP实现的简单日历类。分享给大家供大家参考。具体实现代码如下:复制代码 代码如下:date_default_timezone_set("etc/gmt-8");
header("Content-type: text/html; charset=utf-8");
class calendar{
var $t = array();
var $datesofmonth = array('1'= '31','2'= '28','3'= '31','4'= '30','5'= '31','6'= '30','7'= '31','8'= '31','9'= '30','10'= '31','11'= '30','12'= '31');
var $y,$m,$d;
function set($time){
$this- t = getdate($time);
$this- y = $this- t['year'];
$this- m = $this- t['mon'];
$this- d = date('d',$time);
}
function isrun(){
return ($this- y%400==0 || ($this- y%4==0 && $this- y%100==0)) 1 : 0;
}
function first(){
$time = mktime(0,0,0,$this- m,1,$this-
$time = getdate($time);
return $time['wday'];
}
function html(){
$isrun = $this- isrun();
$this- datesofmonth[2] = $isrun==1 29: 28;
$html .= " table
$html .= " tr th a href='' 上一月 /a /th th colspan='5' {$this- y}年 {$this- m}月 /th th a href='' 下一月 /a /th tr
$html .= " tr td 星期天 /td td 星期一 /td td 星期二 /td phpstudy.net td 星期三 /td td 星期四 /td td 星期五 /td td 星期六 /td /tr
$html .= " tr
$first = $this- first();
for($i=0; $i $first; $i++){
$html .= " td /td
}
$count = $this- datesofmonth[$this- m]+$first;
for ($i=1; $i = $this- datesofmonth[$this- $i++){
$style = $i==$this- d ' ' : '' ;
$html .= " td align='center'{$style} $i /td
if (($i==7%$first || ($i+$first)%7==0) & $count){
$html .= " /tr n tr
}
}
$count = 7-$count%7;
if ($count 7){
for ($i=0; $i $count; $i++){
$html .= " td /td
}
}
$html .= " /tr
$html .= " /table
return $html;
}
}
$calendar = new calendar();
$calendar- set(time());
echo $calendar- html();希望本文所述对大家的php程序设计有所帮助。PHP教程

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表