PHP Practicing: calendar (simple code, easy to expand)

Source: Internet
Author: User
Tags date php class return

Time to write a calendar program, only pay attention to the function and implementation of the idea, so the code and function are relatively simple, but understanding and expansion is also relatively easy.

Show () function to display the calendar, you can modify the show () function, by passing the value of the way to display different years.

 -->'; Echo ''. $year. '-'. $month. ''; Echo 'SundayMondayTuesdayWednesdayThursdayFridaySaturday'; How many days $yearMonth = ' $year ' to get the current month.
            -". $month ';
            $monthNum = $this->getmonthnum ($yearMonth); The first day of the current month is the week $this->firstday = $year. -". $month."
            -01 ";
            $this->firstnum = $this->getweek ($this->firstday);
            
            $this->firstdaynum = $this->weekarray[$this->firstnum]; Echo ''; For ($i =1 $i <= $monthNum + ($this->firstnum); $i + +) {echo '';
                        if ($i >= $this->firstnum+1) {$a = $i-$this->firstnum;
                        if ($a = = $day) {echo '. $a. ';
                        }else{echo '. $a. '; } Echo ''; if ($i%7 = = 0) {//7 columns per output for one line of Echo ''; } Echo '';
    }} $calendar = new calendar (); $calendar->show ();

Effect Chart:

Use of the PHP date () function

Here is a detailed explanation of the date () function: http://wenku.baidu.com/link?url=OPDGzaCMWgjDE0ya8QlDbLIXX0c11ohUjsoLyRm-cYp7lz-O_ 7h4xbilv8jfomhbnsxxsw0fhqxybk0_gn8nr77xmwp-_st7v8ayecbnzjg



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.