Calendar page display

1, Use the mktime() function to get the number of days in the current month and the week on the 1st of the month (2018/3/13)


       

2, Output the header information of the calendar

"; echo""; echo"

{$year}年{$mon}月

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "";

3, Traverse the output calendar

Analysis:

From the mktime() function, we can know the total number of days in the current month. The day of the week is the 1st of the month. It only needs to be less than the total number of days in the current month. Each time, 7-day traversal output is performed.

Start from the day of the week corresponding to the 1st of the month and add 1 every day. The 7-day cycle is one row of data, so the calendar comes out

Code:

"; for($i=1;$i<=7;$i++){//循环输出7天信息 if($d<=$day&&($w<$i||$d!=1)){ echo "
"; $d++; }else{ echo""; } } }

The running results are as follows:

微信图片_20180313153005.png

Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
{$d}