PHP perpetual calendar, php perpetual calendar _ PHP Tutorial

Source: Internet
Author: User
PHP perpetual calendar and php perpetual calendar. PHP perpetual calendar: get the total number of days of the current month to be processed $ days get the first day of the current month to be processed is the day of the week PHP perpetual calendar, php perpetual calendar

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 of 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.

Tips: use PHP to implement perpetual calendar: get the total number of days of the current month to be processed $ days get the number of days of the current month to be processed is the number of days of the week...

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.