// 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'
'. $ Val .' | ';}Echo'
';}// Daylist day listPrivate function daylist (){// Year, month, and day navigationEcho'
';Echo'
Year-1). '& month ='. $ this-> month. '"> < | ';Echo'
Year. '& month ='. ($ this-> month-1). '"> < | ';Echo'
'; Echo' | ';Echo'
Year. '& month ='. ($ this-> month + 1). '"> | ';Echo'
Year + 1). '& month ='. $ this-> month. '">>> | ';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'
'. $ K .' | ';} Else {Echo'
'. $ K .' | ';}If ($ I % 7 = 0 ){If ($ k! = $ This-> days ){Echo'
';}}}Echo'
';}}?>
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 (); ?>
|
|