<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>日历</title>

</head>

    <body>

<?php

//获得地址栏的年份

$year=@$_GET['year'];

//获得地址栏的月份

$month=@$_GET['month'];

//初始化为本年度的年份

if (empty($year))

    $year=date("Y");

//初始化为本年度的月份

if (empty($month))

    $month=date("n");

//获取当天的天数

$day=date("j");

//星期数组

$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 "<table cellpadding=6 cellspacing=0 width=200 bgcolor=#eeeeee><tr align=center bgcolor=#cccccc>";

//输出月份,单击"<"链接跳到上个月,单击">"链接跳到下个月

echo "<td colspan=4><a href='index09b.php?year=$y_lnk1&month=$month'><</a>".$year."<a href='index09b.php?year=$y_lnk2&month=$month'>></a></td>";

echo "<td colspan=3><a href='index09b.php?year=$year&month=$m_lnk1'><</a>".$month."<a href='index09b.php?year=$year&month=$m_lnk2'>></a></td>";

echo "<tr align=center>";

for ($i=0;$i<7;$i++)

{

         echo "<td>$wd_ar[$i]</td>";  //输出星期数组

}

echo "</tr>";

//计算星期几加上当月的天数

$tnum=$wd+date("t",mktime(0,0,0,$month,1,$year));

for ($i=0;$i<$tnum;$i++)

{

         $date=$i+1-$wd;      //计算日数在表格中的位置

         if ($i%7==0)

         echo "<tr align=center>"; //一行的开始

   echo "<td>";

   if ($i>=$wd)

   {

     if ($date==$day&&$month==date("n"))  //如果是当月的当天则将天数加黑

     echo "<b>".$day."</b>";

      else

             echo $date;  //输出日数

   }

   echo "</td>";

   if ($i%7==6)

   echo "</tr>";   //一行结束

}

echo "</table>";

?>

    </body>

</html>