PHP simple way to create a calendar, PHP create calendar _php Tutorial

Source: Internet
Author: User

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. = "
  
  "; $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 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 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 ($ ...

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