Use PHP to generate a calendar
Use PHP to generate a calendar
1.
[File]Calendar. class. php
Year = date ('Y'); $ this-> month = date ('M'); $ vars = get_class_vars (get_class ($ this )); foreach ($ options as $ key =>$ value) {if (array_key_exists ($ key, $ vars) {$ this-> $ key = $ value ;}}} function display () {echo'
'; $ This-> showChangeDate (); $ this-> showWeeks (); $ this-> showDays ($ this-> year, $ this-> month); echo'
';} Private function showWeeks () {echo''; Foreach ($ this-> weeks as $ title) {echo''. $ Title .'';} Echo'';} Private function showDays ($ year, $ month) {$ firstDay = mktime (0, 0, 0, $ month, 1, $ year ); $ starDay = date ('W', $ firstDay); $ days = date ('t', $ firstDay); echo''; For ($ I = 0; $ I <$ starDay; $ I ++) {echo' ';} For ($ j = 1; $ j <= $ days; $ j ++) {$ I ++; if ($ j = date ('D') {echo''. $ J .'';} Else {echo''. $ J .'';} If ($ I % 7 = 0) {echo'';} Echo'';} Private function showChangeDate () {$ url = basename ($ _ SERVER ['php _ SELF']); echo''; Echo'PreYearUrl ($ this-> year, $ this-> month). '">'. '<'.''; Echo'PreMonthUrl ($ this-> year, $ this-> month). '">'. '<'.''; Echo''; Echo'NextMonthUrl ($ this-> year, $ this-> month). '">'. '> '.''; Echo'NextYearUrl ($ this-> year, $ this-> month). '">'. '> '.''; Echo'';} Private function preYearUrl ($ year, $ month) {$ year = ($ this-> year <= 1970 )? 1970: $ year-1; return 'Year = '. $ year. '& month = '. $ month;} private function nextYearUrl ($ year, $ month) {$ year = ($ year >= 2038 )? 2038: $ year + 1; return 'Year = '. $ year. '& month = '. $ month;} private function preMonthUrl ($ year, $ month) {if ($ month = 1) {$ month = 12; $ year = ($ year <= 1970 )? 1970: $ year-1;} else {$ month --;} return 'Year = '. $ year. '& month = '. $ month;} private function nextMonthUrl ($ year, $ month) {if ($ month = 12) {$ month = 1; $ year = ($ year> = 2038 )? 2038: $ year + 1;} else {$ month + +;} return 'Year = '. $ year.' & month = '. $ month ;}}
2.
[File]Demo. php
$ _ GET ['Year'], 'month' => $ _ GET ['month'],);} $ params ['URL'] = 'demo. php '; require_once' calendar. class. php ';?> Calendar demo
Display ();?>
3.
[Image]Sample.jpg