I want to use PHP to generate a calendar of HTML code, and this calendar can be specified in the year automatically generated, the code is too bloated on the internet, or to make one Class
to generate, or there are some I do not want to function.
Is there a streamlined way to generate the calendars I want, like this one?
Reply content:
I want to use PHP to generate a calendar of HTML code, and this calendar can be specified in the year automatically generated, the code is too bloated on the internet, or to make one Class
to generate, or there are some I do not want to function.
Is there a streamlined way to generate the calendars I want, like this one?
|
Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
$V) {if ($k &&!) ( $k% 7)) echo "
"; echo "
{$v} | "; }?>
From your description, you only need to know the number of days of each month for the specified year and the weekly corresponding week.
The Calendar function in PHP can implement the first step:
Http://php.net/manual/zh/function.cal ...
int cal_days_in_month ( int $calendar , int $month , int $year )
HTTP://PHP.NET/MANUAL/ZH/FUNCTION.JDD ...
mixed jddayofweek ( int $julianday [, int $mode = CAL_DOW_DAYNO ] )
All that remains is to write loops through all the months and generate calendars by month.
$begin = new DateTime( '2016-01-01' ); $end = (new DateTime( '2016-12-31' ))->modify( '+1 day' ); $interval = new DateInterval('P1D'); $daterange = new DatePeriod($begin, $interval ,$end); foreach($daterange as $date){ echo $date->format("Y-m-d"). "\n"; }