Simple php calendar control code example

Source: Internet
Author: User

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.

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. = "<table style = 'border: solid 1px black; '> n ";
$ Html. = "<tr> <th> <a href =''> last month </a> </th> <th colspan = '5' >{$ this-> Y} year {$ this-> M} month </th> <a href = ''> next month </a> </th> <tr> n ";
$ Html. = "<tr> <td> Sunday </td> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> thursday </td> <td> Friday </td> <td> Saturday </td> </tr> n ";
$ Html. = "<tr> n ";
$ First = $ this-> first ();
For ($ I = 0; $ I <$ first; $ I ++ ){
$ Html. = "<td> </td> ";
}
$ 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. = "<td align = 'center' {$ style}> $ I </td> ";
If ($ I = 7% $ first | ($ I + $ first) % 7 = 0) & $ I <$ count ){
$ Html. = "</tr> n <tr> ";
}
}
$ Count = 7-$ count % 7;
If ($ count <7 ){
For ($ I = 0; $ I <$ count; $ I ++ ){
$ Html. = "<td> </td> ";
}
}
$ Html. = "</tr> n ";
$ Html. = "</table> n ";
Return $ html;
}
}

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


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.