PHP: a simple way to create a calendar; php: Creating a calendar _ PHP Tutorial

Source: Internet
Author: User
PHP is a simple way to create a calendar. php creates a calendar. PHP is a simple way to create a calendar. php creates a calendar. This document describes how to create a calendar in PHP. For your reference, see phpfunctionbuild_calendar ($ PHP simple calendar creation method, php calendar creation

This example describes how to create a calendar in PHP. We will share this with you for your reference. The details are as follows:

<? Phpfunction build_calendar ($ month, $ year) {// Create array containing abbreviations of days of week. $ daysOfWeek = array ('s ', 'M', 'T', 'W', 'T', 'F','s '); // What is the first day of the month in question? $ FirstDayOfMonth = mktime (0, 0, 0, $ month, 1, $ year); // How many days does this month contain? $ NumberDays = date ('t', $ firstDayOfMonth); // Retrieve some information about the first day of the // month in question. $ dateComponents = getdate ($ firstDayOfMonth); // What is the name of the month in question? $ MonthName = $ dateComponents ['month']; // What is the index value (0-6) of the first day of the // month in question. $ dayOfWeek = $ dateComponents ['wday']; // Create the table tag opener and day headers $ calendar ="
 
 
  
  
"; $ Calendar. ="
  
  "; $ Calendar. ="
  
  
     "; // Create the calendar headers foreach ($ daysOfWeek as $ day) {$ calendar. =" 
    ";}// Create the rest of the calendar // Initiate the day counter, starting with the 1st. $ currentDay = 1; $ calendar. =" 
   
     "; // The variable $ dayOfWeek is used to // ensure that the calendar // display consists of exactly 7 columns. if ($ dayOfWeek> 0) {$ calendar. =" 
    ";}$ Month = str_pad ($ month, 2," 0 ", STR_PAD_LEFT); while ($ currentDay <= $ numberDays) {// Seventh column (Saturday) reached. start a new row. if ($ dayOfWeek = 7) {$ dayOfWeek = 0; $ calendar. =" 
   
     ";}$ CurrentDayRel = str_pad ($ currentDay, 2," 0 ", STR_PAD_LEFT); $ date =" $ year-$ month-$ currentDayRel "; $ calendar. =" 
    "; // Increment counters $ currentDay ++; $ dayOfWeek ++;} // Complete the row of the last week in month, if necessary if ($ dayOfWeek! = 7) {$ remainingDays = 7-$ dayOfWeek; $ calendar. =" 
    ";}$ Calendar. =" 
   "; $ Calendar. =" 
  
$ MonthName $ year
$ Day
$ CurrentDay
"; Return $ calendar;} // call the echo build_calendar ();?>

Shows the running result:

For more information about online display dates, see online tools on this site:

Online Calendar

Web Calendar

Online Calendar, yellow calendar, flash

Related Article

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.