This article is mainly an original PHP calendar control written by a PHP beginner. It can display the current date and the day of the week today, whether it is a leap year, and can automatically select the previous year or the next year. The month and date are also the same.
Simple PHP tutorial calendar control code example
/*
This article is mainly an original PHP calendar control written by a PHP beginner. It can display the current date and what day of the week today is, and whether it is a leap year. The previous year or the next year can be automatically selected, and the month and date are also the same.
*/
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 .= "
Previous month | {$this->Y}year{$ this->M}month | next month | |||
---|---|---|---|---|---|
Sunday | Monday | Tuesday | Wednesday | < td>ThursdayFriday | Saturday |
< /td>"; } $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 .= " | $i | ";||||
$calendar = new Calendar();
$calendar->set(time());
echo $calendar- >html();