PHP Instance ———— Perpetual calendar
To share with you a simple perpetual calendar production process.
Basic requirements:
1. Get the date
2. Get the date given
3. Gets the day of the week for a given date
4. Get the number of months
5. Get the last month and the next month
First paste one, the style is more ugly, do not like to spray.
PHP Code:
";//Get current year $year=$_get[' y ']?$_get[' y ']:d ate (' y '),//Get current month $month=$_get[' m ']?$_get[' m ']:d ate (' m ');//Get how many days in the month $days= Date (' t ', Strtotime ("{$year}-{$month}-1")),//Current Week $week=date (' W ', Strtotime ("{$year}-{$month}-1");//content centered echo "
";//Print header echo"
{$year} year {$month} month
";//Print date form echo"
";//Print Week echo"
echo "
Sunday | ", echo "
Monday | ", echo "
Tuesday | "; echo "
Wednesday | "; echo "
Thursday | "; echo "
Friday | "; echo "
Saturday | "; echo "
"///print the number for ($i =1-$week; $i <= $days;) {echo"
"For ($j =0; $j <7; $j + +) {if ($i > $days | | $i <1) {echo "
| ";} Else{echo "
$i | ";} $i + +;} echo "
";} echo "
";//last month and next month 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;} Hyperlinks in the last month and next January echo "
Last month & next month
"; 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: ' The song Body ';} H2 a{font-style:normal;font-size:40px;font-family: ' blackbody '; color:purple;} /* Combo selector */tr,td,th{font-size:20px;background:gray;}
Some of the more error-prone and ingenious places to say:
The timestamp computed in 1.strtotime () should be a complete format, and it is useless to put a separate year or month in.
2.if statement in the condition inside, not assignment, is equal to!!! , to write two = =. This place is too easy to overlook.
3. The date of the original printing has always been Sunday and one number correspondence. However, the corresponding relationship between the date and week will change in the month, so the $i-$week in the For loop. You can back up all the dates of the month by a certain amount of time, reaching the perfect match for the day of the week.
4. In the implementation of the last month and the next January function, a few variables as parameters, and then with a certain algorithm can be done. The specific look at the code bar, the text is also better than to see two lines of code effect is good.
http://www.bkjia.com/PHPjc/876630.html www.bkjia.com true http://www.bkjia.com/PHPjc/876630.html techarticle PHP Instance ———— Perpetual calendar and we share a simple calendar production process. Basic requirements: 1. Get date 2. Gets the number of the given date 3. Gets the given date is the week of the 4. ...