/**
* PHP Perpetual Calendar
* @author Fly 2012/10/16
*/
class Calendar{
protected $_table;/ /table table
protected $_currentDate; //Current date
protected $_year; //Year
protected $_month; //Month
protected $_days; //The given month should have Number of days
protected $_dayofweek;//What day of the week the 1st of a given month is
/**
* Constructor
*/
public function __construct()
{
$this-> _table="";
$this->_year = isset($_GET["y"])?$_GET["y"]:date("Y");
$this->_month = isset($_GET["m"])?$_GET["m"]:date("m");
if ($this->_month>12){//Handling months greater than 12 Case
$this->_month=1;
$this->_year++;
}
if ($this->_month<1){//Handle the month less than 1 Case
$this->_month=12;
$this->_year--;
}
$this->_currentDate = $this->_year.'year'. $this->_month.'month';//Currently obtained date information
$this->_days = date("t",mktime(0,0,0,$this->_month,1 ,$this->_year));//Get the number of days in a given month
$this->_dayofweek = date("w",mktime(0,0,0,$this-> _month,1,$this->_year));//Get the day of the week that the 1st of a given month is
}
/**
* Output title and header information
*/
protected function _showTitle()
{
$this->_table="
".$this->_currentDate ." |
";
$this->_table.="";
$this->_table .="Sunday | ";
$this->_table .="Monday | ";
$this->_table .="Tuesday | ";
$this->_table .="Wednesday | ";
$ this->_table .="Thursday | ";
$this->_table .="Friday | ";
$this- >_table .="Saturday | ";
$this->_table.="
";
}
/**
* Output date information
* Output date information based on the current date
*/
protected function _showDate()
{
$nums=$this->_dayofweek+1;
for ($i=1;$i< =$this->_dayofweek;$i++){//Output the blank date before the 1st
$this->_table.="  | ";
}
for ($i=1;$i<=$this->_days;$i++){//Output the number of days information
if ($nums%7==0){//Line break processing: 7 per line
$this->_table.="$i | ";
}else{
$this->_table.= "$i | ";
}
$nums++;
}
$this->_table.="
" ;
$this->_table.="
";
}
/**
* Output calendar
*/
public function showCalendar()
{
$this->_showTitle();
$this->_showDate();
echo $this->_table;
}
}
$calc=new Calendar();
$calc->showCalendar();