Simple and practical PHP calendar code-PHP source code

Source: Internet
Author: User
We generally use some js plug-ins to implement the calendar program code, but we will use php programs for log classification like blogs. Let's take a look at the following tutorials for a little introduction. We generally use some js plug-ins to implement the calendar program code, but we will use php programs for log classification like blogs. Let's take a look at the following tutorials for a little introduction.

Script ec (2); script

The PHP calendar program features popular functions. You can pull down and switch the year from the previous year to the next year to the last year to the next year. This is too much easier to scale out, why is the title exquisite? It is because you feel that the interface is still good. Haha, let everyone laugh. Please also point out the shortcomings.

The result code is as follows:

Php calendar core code

The Code is as follows:

// Calendar
Class calendar {
// Current year
Private $ year;
// Current month
Private $ month;
// The first day of a month is the day of the week
Private $ start_weekday;
// Number of days in the current month
Private $ days;
// Maximum and minimum number of years, maximum and minimum number of months
Private $ yearMonth = array (2080,190 0, 12, 1 );
// Constructor
Function _ construct (){
If (isset ($ _ GET ['Year']) {
$ This-> year = $ _ GET ['Year'];
}
If (isset ($ _ GET ['month']) {
$ This-> month = $ _ GET ['month'];
}
$ This-> pnYm ($ this-> year, $ this-> month );
$ This-> days = date ('T', mktime (0, 0, 0, $ this-> month, 1, $ this-> year ));
$ This-> start_weekday = date ('w', mktime (0, 0, 0, $ this-> month, 1, $ this-> year ));
$ This-> style ();
}
// Output
Private function style (){
Echo'




';$ This-> weeklist ();$ This-> daylist ();Echo'














































Echo'






















';}// Date and month Parameter DeterminationPrivate function ymCheck ($ year, $ month ){If (! Is_numeric ($ year )){$ Year = date ('y ');}If (! Is_numeric ($ month )){$ Month = date ('M ');}If ($ month <$ this-> yearMonth [3]) {$ Month = $ this-> yearMonth [2];$ Year-= 1;}If ($ month> $ this-> yearMonth [2]) {$ Month = $ this-> yearMonth [3];$ Year = intval ($ year) + 1;}$ Year = $ year <$ this-> yearMonth [1]? $ This-> yearMonth [1]: $ year;$ Year = $ year> $ this-> yearMonth [0]? $ This-> yearMonth [0]: $ year;Return array ($ year, $ month );}// Last year, next year, last month, and next monthPrivate function pnYm ($ year, $ month ){$ Ym = $ this-> ymCheck ($ year, $ month );$ This-> year = $ ym [0];$ This-> month = $ ym [1];}// Weeklist weekly listPrivate function weeklist (){$ Week = array ('day', 'yi', '2', '3', '4', '5', '6 ');Echo' ';Foreach ($ week as $ val ){Echo' ';}Echo' ';}// Daylist day listPrivate function daylist (){// Year, month, and day navigationEcho' ';Echo' ';Echo' ';Echo' ';Echo' ';Echo' ';Echo' '; ';// Output Space (the space to be blank before the first day of the current month)For ($ I = 0; $ I <$ this-> start_weekday; $ I ++ ){Echo' ';}For ($ k = 1; $ k <= $ this-> days; $ k ++ ){$ I ++;If ($ k = date ('D ')){Echo' ';} Else {Echo' ';}If ($ I % 7 = 0 ){If ($ k! = $ This-> days ){Echo' ';}}}Echo' ';}}?>
'. $ Val .'
Year-1). '& month ='. $ this-> month. '"> <Year. '& month ='. ($ this-> month-1). '"> <';
Echo'
Year. '& month ='. ($ this-> month + 1). '">Year + 1). '& month ='. $ this-> month. '">>>
 '. $ K .''. $ K .'

Html + css code

The Code is as follows:





PHP calendar Program

Script
Function formaction (){
Var form = document. getElementById ('form ');
Form. submit ();
}
Script


Require 'init. php ';
$ Calendar = new calendar ();
?>

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.