<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php日历代码</title>
<style type="text/css">
<!--
#calendarTitle{
width:210px;
}
#calendarMain{
width:210px;
}
.clear{
clear:both;
}
.titleSpan{
width:30px;
text-align:center;
float:left;
}
.daySpan{
width:30px;
text-align:center;
float:left;
}
-->
</style>
</head>
<body>
<div id="calendarTitle">
<div class="titleSpan">日</div>
<div class="titleSpan">一</div>
<div class="titleSpan">二</div>
<div class="titleSpan">三</div>
<div class="titleSpan">四</div>
<div class="titleSpan">五</div>
<div class="titleSpan">六</div>
<div class="clear"></div>
</div>
<div id="calendarMain">
<?
@date_default_timezone_set('+8');
function week2day($str) {
$days = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
return array_search($str, $days) + 1;
}
$selectTimestamp = time();
$curMonth = date('n', $selectTimestamp);
$curYear = date('Y', $selectTimestamp);
$curDay = week2day(date('D', $selectTimestamp));
$todayNum = date('j', $selectTimestamp);
$curMonthTotal = date('t', $selectTimestamp);
$firstDay = week2day(date('D', mktime(0,0,0,$curMonth,1,$curYear)));
$lastDay = week2day(date('D', mktime(0,0,0,$curMonth,$curMonthTotal,$curYear)));
for($i=0;$i<$firstDay;$i++){
echo('<div class="daySpan"> </div>');
}
for($i=1;$i<=$curMonthTotal;$i++){
if($i == $todayNum){
echo('<div class="daySpan">X</div>');
}else{
echo('<div class="daySpan">'.$i.'</div>');
}
}
?>
</div>
<div class="clear"></div>
</body>
</html>