PHP million calendar implementation program code

Source: Internet
Author: User

The essentials of using PHP to realize the calendar function:

• Get the total number of days of the month currently to be processed $days
• Get the number of the month that is currently being processed is the week $dayofweek
$days role: Know how many days to process the month, you can output the number of days by cycle

$dayofweek role: Only know the number of days per month is the day of the week, to know how many spaces to output before the number (blank)

The code is as follows Copy Code

<?php
/**
* PHP million calendar
* @author Fly 2012/10/16
*/
Class calendar{
Protected $_table;//table Form
Protected $_currentdate;//Current Date
protected $_year; Years
protected $_month; Month
protected $_days; The number of days due for a given month
Protected $_dayofweek;//number 1th for a given month is the day of the week.
/**
* Constructor
*/
Public Function __construct ()
{
$this->_table= "";
$this->_year = isset ($_get["y"])? $_get["Y"]:d ate ("Y");
$this->_month = isset ($_get["M"])? $_get["M"]:d ate ("M");
if ($this->_month>12) {//processing occurs when the month is greater than 12
$this->_month=1;
$this->_year++;
}
if ($this->_month<1) {//processing occurs when the month is less than 1
$this->_month=12;
$this->_year--;
}
$this->_currentdate = $this->_year. ' Year '. $this->_month. ' Month '; current 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)); number 1th for the given month is the day of the week.
}
/**
* Output Header and header information
*/
protected function _showtitle ()
{
$this->_table= "<table><thead><tr align= ' center ' ><th colspan= ' 7 ' >". $this->_ currentdate. " </th></tr></thead> ";
$this->_table.= "<tbody><tr>";
$this->_table. = "<td style= ' color:red ' > Sunday </td>";
$this->_table. = "<td> Monday </td>";
$this->_table. = "<td> Tuesday </td>";
$this->_table. = "<td> Wednesday </td>";
$this->_table. = "<td> Thursday </td>";
$this->_table. = "<td> Friday </td>";
$this->_table. = "<td style= ' color:red ' > Saturday </td>";
$this->_table.= "</tr>";
}
/**
* Output date information
* Output date information based on current date
*/
protected function _showdate ()
{
$nums = $this->_dayofweek+1;
For ($i =1 $i <= $this->_dayofweek; $i + +) {//blank date before 1th #
$this->_table.= "<td>&nbsp</td>";
}
For ($i =1 $i <= $this->_days; $i + +) {//Output days information
if ($nums%7==0) {//linefeed processing: 7 rows
$this->_table.= "<td> $i </td></tr><tr>";
}else{
$this->_table.= "<td> $i </td>";
}
$nums + +;
}
$this->_table.= "</tbody></table>";
$this->_table.= "$this->_table.= "<a href= '? y=". ($this->_year). " &m= ". ($this->_month+1). "' > next month </a>}
/**
* Output Calendar
*/
Public Function Showcalendar ()
{
$this->_showtitle ();
$this->_showdate ();
Echo $this->_table;
}
}
$calc =new Calendar ();
$calc->showcalendar ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.