Simple PHP Tutorial Calendar class control Code instance
/*
This article is mainly a PHP beginner wrote the original PHP Calendar control, you can show the current date and today is the day of the week, whether it is a leap year, can automatically select the previous year or next, the month date is the same.
*/
Date_default_timezone_set ("etc/gmt-8");
Class calendar{
var $T = array ();
var $datesOFmonth = Array (' 1 ' => ', ' 2 ' => ', ' 3 ' => ', ' 4 ' => ', ' 5 ' => ', ' 6 ' => ', ' 7 ' => ') ' 8 ' => ', ' 9 ' => ', ' => ', ' One ' => ', ' => ' 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 A () {
$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. = "< Table style= ' Border:solid 1px black; >n ";
$html. = "<tr><th><a href= ' > Last month </a></th><th colspan= ' 5 ' >{$this->y} years THIS->M} month </th><th><a href= ' > next month </a></th><tr>n ';
$html. = "<tr><td> Sunday </td><td> Monday </td><td> Tuesday </td><td> Wednesday </td><td> Thursday </td><td> Friday </td><td> Saturday </td></tr>n ";
$html. = "<tr>n";
$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->m]; $i + +) {
$style = $i = = $this->d? ' style= ' color:red;font-weight:bold; "': ';
$html. = "<td align= ' center ' {$style}> $i </td>";
if ($i ==7% $first || ($i + $first)%7==0) && $i < $count) {
$html. = "</tr>n<tr>";
}
}
$count = 7-$count%7
if ($count <7) {
for ($i =0; $i < $count; $i + +) {
$html. = "<td></td > ";
}
$html. = "</tr>n";
$html. = "</table>n";
return $html;
}
}
$calendar = new Calendar ();
$calendar->set (Time ());
Echo $calendar->html ();