一聚教程网:一个值得你收藏的教程网站

热门教程

简单的php日历类控件代码实例

时间:2022-06-24 18:34:51 编辑:袖梨 来源:一聚教程网

简单的php教程日历类控件代码实例
/*

*/
date_default_timezone_set("Etc/GMT-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->Y);
$time = getdate($time);
return $time['wday'];
}

function html(){
$isRun = $this->isRun();
$this->datesOFmonth[2] = $isRun==1 ? 29: 28;
$html .= "

n";
$html .= "n";
$html .= "n";
$html .= "n";
$first = $this->first();
for($i=0; $i<$first; $i++){
$html .= "";
}
$count = $this->datesOFmonth[$this->M]+$first;
for ($i=1; $i<= $this->datesOFmonth[$this->M]; $i++){
$style = $i==$this->D ? ' style="color:red;font-weight:bold;"' : '' ;
$html .= "";
if (($i==7%$first || ($i+$first)%7==0) && $i<$count){
$html .= "n";
}
}
$count = 7-$count%7;
if ($count<7){
for ($i=0; $i<$count; $i++){
$html .= "";
}
}
$html .= "n";
$html .= "
上一月{$this->Y}年 {$this->M}月下一月
星期天星期一星期二星期三星期四星期五星期六
$i
n";
return $html;
}
}

$calendar = new Calendar();
$calendar->set(time());
echo $calendar->html();

热门栏目