PHP Perpetual Calendar

Source: Internet
Author: User
This article mainly introduces how to use PHP to create perpetual calendar and several key points for implementing this function and provides all the source code. We recommend it to our partners here.

This article mainly introduces how to use PHP to create perpetual calendar and several key points for implementing this function and provides all the source code. We recommend it to our partners here.

Key points for implementing the Perpetual Calendar function using PHP:

Returns the total number of days of the current month to be processed. $ days
Get the number one of the months to be processed is the day of the week $ dayofweek
$ Days: If you know the total number of days of the month to be processed, You can output the number of days in a loop.

$ Dayofweek: only when the first day of each month is the day of the week can we know how many spaces (blank) need to be output before the number of days to be output)

The final result is as follows:

The code for "Perpetual Calendar" is as follows:

The Code is as follows:


<? Php
/**
* 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 of the given month
Protected $ _ dayofweek; // the day of the week on the first day of the 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) {// process the case where the month is greater than 12
$ This-> _ month = 1;
$ This-> _ year ++;
}
If ($ this-> _ month <1) {// process the case where the month is smaller 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 )); // obtain the number of days of the given month
$ This-> _ dayofweek = date ("w", mktime (0, 0, $ this-> _ month, 1, $ this-> _ year )); // obtain the number 1 of the given month as the 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 1$ This-> _ table. =" ";}For ($ I = 1; $ I <= $ this-> _ days; $ I ++) {// output the number of daysIf ($ nums % 7 = 0) {// line feed processing: 7 rows$ This-> _ table. =" ";} Else {$ This-> _ table. =" ";}$ Nums ++;}$ This-> _ table. ="
". $ This-> _ currentDate ."
SundayMondayTuesdayWednesdayThursdayFridaySaturday
 $ I
$ I
";
$ This-> _ table. = "_ year)." & m = ". ($ this-> _ month-1)." '> last month ";
$ This-> _ table. = "_ year)." & m = ". ($ this-> _ month + 1)." '> next month ";
}
/**
* Output calendar
*/
Public function showCalendar ()
{
$ This-> _ showTitle ();
$ This-> _ showDate ();
Echo $ this-> _ table;
}
}
$ Calc = new Calendar ();
$ Calc-> showCalendar ();

The effect is not bad. You can make your friends more beautiful.

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.