PHP Design Calendar Class One (38)
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 year Private$month;//the current month Private$start _weekday;//The first day of the month corresponds to the week Private$days;//The current month altogether how many daysfunction __construct () {$ This->year=isset ($_get[" Year"]) ? $_get[" Year"]: Date ("Y"); $ This->month=isset ($_get["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}&month={$month}
"
; }
Private
function Prevmonth ($year, $month) {
if($month = =
1
) {$year= $year-
1
;
if($year <
1970
) $year=
1970
; $month=
A
; }
Else
{$month--
; }
return
"
year={$year}&month={$month}
"
; }
Private
function Nextyear ($year, $month) {$year= $year +
1
;
if($year >
2038
) $year=
2038
;
return
"
year={$year}&month={$month}
"
; }
Private
function Nextmonth ($year, $month) {
if($month = =
A
) {$year++
;
if($year >
2038
) $year=
2038
; $month=
1
; }
Else
{$month++
; }
return
"
year={$year}&month={$month}
"
; }
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: