Consists of two files:
The first of the test.php
PHP "calendar.class.php"; $calendar=new calendar; $calendar-out ();
Second Calendar class: calendar.class.php
PhpclassCalendar {Private$year;//the current yearPrivate$month;//the current monthPrivate$start _weekday;//The first day of the month corresponds to the weekPrivate$days;//The current month altogether how many daysfunction __construct () {$ This->year=isset ($_get[" Year"]) ? $_get[" Year"]: Date ("Y"); $ This->m> "Month"]) ? $_get["Month"]: Date ("m"); $ This->start_weekday=date ("W", Mktime (0,0,0, $ This->month,1, $ This-Year )); $ This->days=date ("T", Mktime (0,0,0, $ This->month,1, $ This-Year )); } function out() {echo''; $this"test.php"); $thisweekslist (); $thisdayslist (); echo '
'; } Privatefunction Weekslist () {$week=array ('Day','a','two','three','Four','Five','Six'); Echo''; for($i =0; $i
) echo
'
'. $week [$i].
'
'
; Echo
'
'
; }
Private
function Dayslist () {echo
'
'
;
//
output Space (the first day of the current January will be empty)
for($j =
0; $j <$
This->start_weekday; $j + +
) echo
'
'
;
for($k =
1; $k <=$
This->days; $k + +
) {$j++
;
if($k ==date (
'
D
'
)) echo
'
'. $k.
'
'
;
Else
Echo
'
'. $k.
'
'
;
if($j%
7==
0
) echo
'
'
; }
//
several spaces behind
while($j%
7!==
0
) {echo
'
'
; $j++
; } Echo
'
'
; }
Private
function Prevyear ($year, $month) {$year= $year-
1
;
if($year <
1970
) $year=
1970
;
return
"
year={$year}&m/span>"; } Privatefunction Prevmonth ($year, $month) {if($month = =1) {$year= $year-1; if($year <1970) $year=1970; $month= A; }Else{$month--; } return"year={$year}&m/span>"; } Privatefunction Nextyear ($year, $month) {$year= $year +1; if($year >2038) $year=2038; return"year={$year}&m/span>"; } Private function Nextmonth ($year, $month) { if($m >12) {$year++; if($year >2038) $year=2038; $month=1; }Else{$month++; } return"year={$year}&m/span>"; } Privatefunction Chagedate ($url ="") {echo''; Echo''.$ This->prevyear ($ This->year, $ This->month).'">'.'<<'.''; Echo''.$ This->prevmonth ($ This->year, $ This->month).'">'.'<'.''; Echo''; Echo''; Echo''; Echo' '. $ this->nextyear ($this->year, $this->month). ' "> '. ' >> '. ' '; ' echo '. $This->nextmonth ($This ->year, $this->month). ' "> '. ' > '. ' '; Echo ';}}
Effect:
The above describes the PHP design calendar class One (38), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.