<?php
if(empty($year))$year=date("Y"); //初始化年份
if(empty($month))$month=date("n"); //初始化月份
$wd_ar=array("日","一","二","三","四","五","六"); //星期数组
$wd=date("w",mktime(0,0,0,$month,1,$year)); //当月第一天是星期几
//年链接
$y_lnk1=$year<=1970?$year=1970:$year-1;
$y_lnk2=$year>=2037?$year=2037:$year+1;
//月链接
$m_lnk1=$month<=1?$month=1:$month-1;
$m_lnk2=$month>=12?$month=12:$month+1;
echo <<< EOT
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#00FF00" width="600" bgcolor="#eeeeee"> <tr align="center" bgcolor="#cccccc">
<td colspan="4" height="35"><a href="$php_self?year=$y_lnk1&month=$month"><</a> $year 年 <a href="$php_self?year=$y_lnk2&month=$month">></a></td>
<td colspan="3" height="35"><a href="$php_self?year=$year&month=$m_lnk1"><</a> $month 月 <a href="$php_self?year=$year&month=$m_lnk2">></a></td> </tr> <tr align="center">
EOT;
for($i=0;$i<7;$i++) {
print "<td height=35>$wd_ar[$i]</td> ";
}
print "</tr> ";
$tnum=$wd+date("t",mktime(0,0,0,$month,1,$year));
for($i=0;$i<$tnum;$i++) {
$date=$i+1;
if($i%7==0) print '<tr align="center">';
print '<td height="75">';
if($i>=$wd) print $date-$wd;
print "</td> ";
if($i%7==6) print "</tr> ";
}
if($i%7<6 && $i%7>0) print '<td colspan="".(7-$i%7).""></td> </tr> ';
if($i%7==6) print "<td></td> </tr> ";
print '</table>';
?>