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. ="
$ MonthName $ year
"; $ Calendar. ="
"; // Create the calendar headers foreach ($ daysOfWeek as $ day) {$ calendar. ="
$ Day | ";}// 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. ="
$ CurrentDay | "; // Increment counters $ currentDay ++; $ dayOfWeek ++;} // Complete the row of the last week in month, if necessary if ($ dayOfWeek! = 7) {$ remainingDays = 7-$ dayOfWeek; $ calendar. ="
| ";}$ Calendar. ="
"; $ Calendar. ="
"; 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