html-php how to generate a calendar year in a specified year

Source: Internet
Author: User
Tags php foreach

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?

 
 
 
  $V) {if ($k &&!) ( $k% 7)) echo " 
   
     "; echo " 
    "; }?> 
   
Sun Mon Tue Wed Thu Fri Sat
{$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";    }
  • Related Article

    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.