<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>日历程序</title>
</head>
<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()"
>
<?php
$selectedDay = date('d');
$selectedMonth = date('m');
$selectedYear = date('Y');
//获得当月第一天数据型星期几
$firstday = date('w',mktime(0,0,0,$selectedMonth,1,$selectedYear));
//获取当月最后一天
$lastday = 31;
do{
$monthOrig = date('m',mktime(0,0,0,$selectedMonth,1,$selectedYear));
$monthTest = date('m',mktime(0,0,0,$selectedMonth,$lastday,$selectedYear));
if($monthTest != $monthOrig){$lastday -= 1;}
}while($monthTest != $monthOrig);
//获得当月对应的英文名
$monthName = date('F',mktime(0,0,0,$selectedMonth,1,$selectedYear));
//显示日历头
$days = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
$dayRow = 0;
echo "<table bgcolor=\"#bbffff\">";
echo "<caption valign=\"center\"><b>$selectedYear $monthName</b></caption>";
echo "<tr>\n";
for($i=0;$i<=6;$i++){
echo "<td width=10%>$days[$i]</td>\n";
}
echo "</tr>\n";
echo "</tr>\n";
//空出当月第一天的位置
while($dayRow < $firstday){
echo "<td></td>";
$dayRow += 1;
}
$day = 0;
while($day < $lastday){
if(($dayRow % 7) == 0){
echo "</tr>\n<tr>\n";
}
$adjusted_day = $day + 1;
//当天用红色表示
if($adjusted_day == $selectedDay){
echo "<td><font color=#ff0000>$adjusted_day</font></td>";
}
else {
echo "<td>$adjusted_day</td>";
}
$day += 1;
$dayRow += 1;
}
echo "\n</tr>\n</table>";
?>
</body>
</html>
(非常全面的一个php技术网站, 有相当丰富的文章和源代码.)
|