PHP Instance ———— Perpetual calendar

Source: Internet
Author: User

And everyone to share a simple calendar production process.

Basic requirements:

1. Date of acquisition

2. Get the date given

3. Get a given date is a week

4. Get Month days

5. Access to previous and next month

First put a picture of the effect, the style to do more ugly, do not like to spray.


PHP Code:

 -->";

	Gets the current year $year =$_get[' y ']?$_get[' y ']:d ate (' Y ');

	Gets the current month $month =$_get[' m ']?$_get[' m ']:d ate (' m ');

	Gets how many days of the month $days =date (' t ', Strtotime ("{$year}-{$month}-1"));

	Current is the week $week =date (' W ', Strtotime ("{$year}-{$month}-1")); Content centered Show echo "
 
  
   "; Print header echo "
   

{$year} year {$month} month

"; Print Date table echo " "; Print Week echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; Print a number for ($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
"; The previous month and the 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; //Last month and next January hyperlinks 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: ' song body ';
}
H2 a{
	font-style:normal;
	font-size:40px;
	font-family: ' blackbody ';
	color:purple;
}
/* Combination Selector *
	/tr,td,th{font-size:20px;
	Background:gray;
}

A few of the more error-prone and ingenious places to say:

The time stamp calculated in 1.strtotime () should be a complete format, and it is useless to put a single year or month in.

In the 2.if statement, the condition is not assigned, is equal to!!! , write two = =. This place is too easy to overlook.

3. The original print date has always been Sunday and a corresponding number. But when the month is different, the corresponding relationship between the date and the week changes, so the $i-$week in the For loop. You can take all the days of the month back a certain amount of time, to achieve the perfect correspondence between the date and the week.

4. In the implementation of the previous month and the next January function, several variables as parameters into, and then with a certain algorithm can be done. The specific look at the code, the text has to be better than to see two lines of code effect good.




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.