Make a perpetual calendar with PHP, php perpetual calendar_PHP tutorial

WBOY
Release: 2016-07-13 10:10:06
Original
1747 people have browsed it

PHP production perpetual calendar, php perpetual calendar

Key points of using PHP to implement the perpetual calendar function:

Get the total number of days in the current month to be processed $days
Get the day of the week that the first day of the month to be processed is $dayofweek
The role of $days: knowing how many days there are in the month to be processed, you can output the number of days through a loop

The role of $dayofweek: Only by knowing the day of the week on the 1st of each month can we know how many spaces (blanks) need to be output before outputting the number of days

The final rendering is as follows:

The code of "perpetual calendar class" is as follows:

Copy code The code is as follows:

/**
* PHP Perpetual Calendar
* @author Fly 2012/10/16
​*/
class Calendar{
Protected $_table;//table
Protected $_currentDate;//Current date
Protected $_year; //Year
Protected $_month; //Month
Protected $_days; //Number of days in a given month
protected $_dayofweek;//What day of the week is the 1st of a given month
/**
* 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){//Handle the situation where the month is greater than 12
                 $this->_month=1;
                $this->_year++;
}
If ($this->_month<1){//Handle the situation where the month is less than 1
$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 1st of the given month Day of the week
}
/**
* Output title and header information
​​*/
Protected function _showTitle()
{
$this->_table="";
           $this->_table.="";
           $this->_table .="";
           $this->_table .="";
             $this->_table .="";
            $this->_table .="";
            $this->_table .="";
            $this->_table .="";
           $this->_table .="";
           $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 days information
                if ($nums%7==0){//Line break processing: 7 per line
                $this->_table.="";   
            }else{
                $this->_table.="";
            }
            $nums++;
        }
        $this->_table.="
".$this->_currentDate."
SundayMondayTuesdayWednesdayThursdayFridaySaturday
 $i
$i
";
        $this->_table.="

上一月   ";
        $this->_table.="下一月

";
    }
    /**
* * Output calendar
​​*/
    public function showCalendar()
    {
        $this->_showTitle();
        $this->_showDate();
        echo $this->_table;
    }
}
$calc=new Calendar();
$calc->showCalendar();

效果还不错吧,小伙伴们还可以自己美化下,这里就不多做说明了。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/939405.htmlTechArticlePHP制作万年历,php万年历 使用PHP实现万年历功能的要点: 得到当前要处理的月份总共有多少天$days 得到当前要处理的月份的一号是星期几...
Related labels:
php
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!