按月显示的日历

<? 
function build_calendar_table($year=0$month=0$day=0

global 
$PHP_SELF

$cal ""

if (
$year==0$year date('Y')+0
if (
$month==0$month date('m')+0
if (
$day==0$day date('d')+0

$pyear = ($month==1?$year-1:$year); 
$pmonth = ($month==1?12:$month-1); 

$nyear = ($month==12?$year+1:$year); 
$nmonth = ($month==12?1:$month+1); 

$firstday mktime(0,0,0,$month1$year); 
$skip date('w'$firstday); 
$dim date('t'$firstday); 
$rows ceil(($skip+$dim) / 7); 
# echo $rows; 

$cal .= "\n<TABLE WIDTH=160 BORDER=0 CELLPADDING=1 CELLSPACING=1>"
$cal .= "\n<TR><TD COLSPAN=7 ALIGN=CENTER>"
$cal .= '<A HREF="'."$PHP_SELF?year=$pyear&month=$pmonth".'">prev</A>&nbsp;'
$cal .= $year.'/'.$month
$cal .= '&nbsp;<A HREF="'."$PHP_SELF?year=$nyear&month=$nmonth".'">next</A>'
$cal .= "\n</TD></TR>"
$cal .= "\n<TR ALIGN=CENTER>"
$cal .= "\n<TD>S</TD><TD>M</TD><TD>T</TD><TD>W</TD><TD>T</TD><TD>F</TD><TD>S</TD>"
$cal .= "\n</TR>"

for (
$row=0$row<$rows$row++) 

$cal.= "\n<TR ALIGN=CENTER>"
for (
$col=0$col<7$col++) 

$cur $row*7+$col-$skip+1
$cal .= "\n<TD"
if (
$year==(int)date('Y')&&$month==(int)date('m')&&$cur==(int)date('d')) 
$cal.= " BGCOLOR=#D0D0D0 "
$cal .= '>'
if (
$row*7+$col<$skip
$cal.= "&nbsp;"
else 

if (
$cur>$dim
$cal .= '&nbsp;'
else 

if (
$year==(int)date('Y')&&$month==(int)date('m')&&$cur==$day
$cal.= '<b>'
$cal .= '<A HREF="'."$PHP_SELF?year=$year&month=$month&day=$cur".'">'.$cur.'</A>'
if (
$year==(int)date('Y')&&$month==(int)date('m')&&$cur==$day
$cal.= '</b>'


$cal .= "</TD>"

$cal.= "\n</TR>"


$cal .= "\n</TABLE>"

echo 
$cal