Home  >  Article  >  Backend Development  >  Simple calendar class implemented in PHP, calendar implemented in php_PHP tutorial

Simple calendar class implemented in PHP, calendar implemented in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:12:46952browse

Simple calendar class implemented in PHP, calendar implemented in php

The example in this article describes a simple calendar class implemented in PHP. Share it with everyone for your reference.

The specific implementation code is as follows:

Copy code The code is as follows:
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->y);
$time = getdate($time);
return $time['wday'];
}
function html(){
$isrun = $this->isrun();
$this->datesofmonth[2] = $isrun==1 ? 29: 28;
$html .= "n";
$html .= "n" ;
$html .= "jb51.netn";
$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 .= "
Previous month{$this-> ;y}year{$this->m}monthnext month
SundayMondayTuesdayWednesdayThursdayFridaySaturday
$i
n";
return $html;
}
}
$calendar = new calendar();
$calendar->set(time());
echo $calendar->html();

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/919618.htmlTechArticleSimple calendar class implemented in PHP, calendar implemented in php This article describes the simple calendar class implemented in PHP. Share it with everyone for your reference. The specific implementation code is as follows: Copy the code The code is as follows...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn