Simple php calendar control code example _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Simple php calendar control code example. This article is mainly an original php calendar control written by a beginner in php. it can display the current date and today's day of the week, whether it is a leap year, and automatically select the previous or next year, month/Day This article is mainly an original php calendar control written by a beginner in php. it can display the current date and today's day of the week, whether it is a leap year, you can automatically select the previous year or the next year, the same is true for month and date.

Simple php Tutorial calendar control code example
/*
This article is mainly an original php calendar control written by a beginner in php. it can display the current date and today's day of the week, whether it is a leap year, and automatically select the previous or next year, the same is true for month and date.
*/
Date_default_timezone_set ("Etc/GMT-8 ");

Class Calendar {

Var $ T = array ();
Var $ datesOFmonth = array ('1' => '31', '2' => '28', '3' => '31 ', '4' => '30', '5' => '31', '6' => '30', '7' => '31 ', '8' => '31', '9' => '30', '10' => '31', '11' => '30 ', '12' => '31 ');
Var $ Y, $ M, $ D;

Function set ($ time ){
$ This-> T = getdate ($ time );
$ This-> Y = $ this-> T ['Year'];
$ This-> M = $ this-> T ['mon'];
$ This-> D = date ('D', $ time );
}

Function isRun (){
Return ($ this-> Y % 400 = 0 | ($ this-> Y % 4 = 0 & $ this-> Y % 100 = 0 ))? 1: 0;
}

Function first (){
$ Time = mktime (0, 0, 0, $ this-> M, 1, $ this-> Y );
$ Time = getdate ($ time );
Return $ time ['wday'];
}

Function html (){
$ IsRun = $ this-> isRun ();
$ This-> datesOFmonth [2] = $ isRun = 1? 29: 28;
$ Html. ="
























N ";$ Html. =" N ";$ Html. =" N ";$ Html. =" N ";$ First = $ this-> first ();For ($ I = 0; $ I <$ first; $ I ++ ){$ Html. =" ";}$ Count = $ this-> datesOFmonth [$ this-> M] + $ first;For ($ I = 1; $ I <= $ this-> datesOFmonth [$ this-> M]; $ I ++ ){$ Style = $ I ==$ this-> D? 'Style = "color: red; font-weight: bold ;"':'';$ Html. =" ";If ($ I = 7% $ first | ($ I + $ first) % 7 = 0) & $ I <$ count ){$ Html. =" N ";}}$ Count = 7-$ count % 7;If ($ count <7 ){For ($ I = 0; $ I <$ count; $ I ++ ){$ Html. =" ";}}$ Html. =" N ";$ Html. ="
Last month {$ This-> Y} year {$ this-> M} month Next month
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
$ I
N ";
Return $ html;
}
}

$ Calendar = new Calendar ();
$ Calendar-> set (time ());
Echo $ calendar-> html ();


Week, the current date and today are the day of the week, whether it is a leap year, you can automatically select the previous year or next year, month and day...

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.