PHP simple way to create a calendar, PHP create a calendar
This article describes a simple way to create a calendar in PHP. Share to everyone for your reference, 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's 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's the name of the month in question? $monthName = $dateComponents [' Month ']; What's 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 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 method Echo Build_calendar (05,2016);? >
The results of the operation are as follows:
For online display of the date can also refer to the site online tools:
Online Perpetual calendar
Web Perpetual calendar
Online Perpetual Calendar Almanac Flash Edition
More readers interested in PHP related content can view the topic: "PHP Date and Time usage summary", "PHP Math Skills Summary", "PHP array" operation Skills Daquan, "PHP Object-oriented Programming tutorial", "PHP string" Summary of usage, Introduction to PHP+MYSQL database operation and PHP common database operation Skills Summary
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1125242.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125242.html techarticle php Simple way to create a calendar, PHP create a calendar This article describes the simple way to create a calendar PHP. Share to everyone for your reference, as follows: Phpfunction Build_calendar ($ ...