下边是我的代码。使用html和php混编的,保存文件名为php文件calendar.php,单独运行时没问题的,可是贴不到自己的网站首页上去。
<?php
$now_year = date("Y");
$now_month = date("n");
$now_day = date("j");
$first_day = mktime( 0, 0, 0, $now_month, 1, $now_year );
$first_weekday = date( "w", $first_day );
?>
<?=$now_year?>年<?=$now_month?>月
<table border=1>
<tr bgcolor="#add8e6">
<th><font color=red>星期天</font></th>
<th><font color=black>星期一</font></th>
<th><font color=black>星期二</font></th>
<th><font color=black>星期三</font></th>
<th><font color=black>星期四</font></th>
<th><font color=black>星期五</font></th>
<th><font color=blue>星期六</font></th>
</tr>
<?php
echo "<tr>";
$weekday = 0;
while( $weekday != $first_weekday ){
echo "<td> </td>";
$weekday++;
}
for( $day = 1; checkdate( $now_month, $day, $now_year ); $day++ ){
if( $weekday > 6 ){
$weekday = 0;
echo "</tr>\n<tr>";
}
switch( $weekday ){
case 0 :
$color = "red";
break;
case 6 :
$color = "blue";
break;
default :
$color = "black";
}
if($day == $now_day){
echo "<td align=center bgcolor=\"#98fb98\"><font color=${color}>${day}</font></td>";
}
else {
echo "<td align=center><font color=${color}>${day}</font></td>";
}
$weekday++;
}
while( $weekday < 7 ){
echo "<td> </td>";
$weekday++;
}
echo "</tr>\n";
?>
</table>