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"
Sunday | "; Echo"
Monday | "; Echo"
Tuesday | "; Echo"
Wednesday | "; Echo"
Thursday | "; Echo"
Friday | "; Echo"
Saturday | "; 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 | ";}$ I ++;} echo"
";} Echo"
"; // 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...