Simple PHP calendar control code example_PHP tutorial

WBOY
Release: 2016-07-20 11:07:47
Original
1161 people have browsed it

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 .= "

n";
$html .= "< ;tr>n";
$html .= "< td>Thursdayn";
$html .= "n" ;
$first = $this->first();
for($i=0; $i<$first; $i++){
$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 .= "< td>";
}
}
$html .= "n";
$html .= "
Previous month{$this->Y}year{$ this->M}monthnext month
SundayMondayTuesdayWednesdayFridaySaturday
< /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
n";
return $html;
}
}

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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444926.htmlTechArticleThis article is mainly an original php calendar control written by a php beginner, which can display the current date and today’s day of the week Whether it is a leap year or not, you can automatically select the previous year or the next year, month and day...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!