PHP instance ---- perpetual calendar _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags php example
PHP instance ---- perpetual calendar. PHP example-perpetual calendar: a simple perpetual calendar creation process. Basic requirements: 1. get the date 2. get the number of the given date 3. get the number of weeks for the given date 4. get the PHP instance ---- perpetual calendar

We will share with you a simple perpetual calendar creation process.

Basic requirements:

1. get date

2. obtain the number of the given date

3. obtain the number of weeks for a given date.

4. obtain the number of days in a month

5. obtain

Paste one first, and the style is ugly.


Php code:

 "; // GET the current year $ year =$ _ GET ['Y']? $ _ GET ['Y']: date ('Y'); // GET the current month $ month = $ _ GET ['M']? $ _ GET ['M']: date ('M'); // Obtain the number of days in the current month. $ days = date ('t ', strtotime ("{$ year}-{$ month}-1"); // The current week $ week = date ('W ', strtotime ("{$ year}-{$ month}-1"); // echo is displayed in the center of the content"
 
  
"; // Print the header echo" {$ year}-{$ month}-month "; // Print the date table echo"
  
 
  
   
"; // Print Weekly echo"
   
  
     "; Echo" 
    "; Echo" 
    "; Echo" 
    "; Echo" 
    "; Echo" 
    "; Echo" 
    "; Echo" 
    "; Echo" 
   "; // Print the number ($ I = 1-$ week; $ I <= $ days;) {echo" 
   
     "; For ($ j = 0; $ j <7; $ j ++) {if ($ I> $ days | $ I <1) {echo" 
    ";} Else {echo" 
    ";}$ I ++;} echo" 
   ";} Echo" 
  
SundayMondayTuesdayWednesdayThursdayFridaySaturday
 $ I
"; // Algorithm if ($ month = 1) {$ prevyear = $ year-1; $ prevmonth = 12 ;} else {$ prevyear = $ year; $ prevmonth = $ month-1;} if ($ month = 12) {$ nextyear = $ year + 1; $ nextmonth = 1 ;} else {$ nextyear = $ year; $ nextmonth = $ month + 1;} // The hyperlink echo "last January & next January"; echo" ";?>

CSS code:

Table {width: 500px; height: 300px; border: red dashed 1px; background: # ff00ff ;}tr {text-align: center ;}td {border: gray dotted 1px ;} h1 {font-style: italic; font-size: 50px; font-family: ' ';} h2 a {font-style: normal; font-size: 40px; font-family: 'simhei '; color: purple;}/* combination selector */tr, td, th {font-size: 20px; background: gray ;}

Here are some points that are more error-prone and clever to use:

1. the timestamp calculated in strtotime () should be in a complete format. it is useless to put a separate year or month in it.

2. in the if statement, the condition is not a value, which is equal !!!, Write two =. This place is too easy to ignore.

3. the printed date always corresponds to Sunday and Day 1. However, when the month is different, the correspondence between the date and the week will also change. Therefore, in the for loop, $ I-$ week. in this way, all the dates of the current month can be regressed by a certain time to reach the perfect match between the date and the week.

4. when implementing the functions of January and January, we can bring several variables into the system as parameters, and then work with certain algorithms. Let's take a look at the code. The text is better than the two lines of code.


Ghost will share with you a simple perpetual calendar creation process. Basic requirements: 1. get the date 2. get the number of the given date 3. get the number of weeks for the given date 4. get...

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.