$weekArr = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
//获取空格:
//echo date("D",strtotime("2012-02-07"));
function getSpace($month,$year=''){
global $weekArr;
if(!$year){
$year = date("Y");
}
$firstDay = date("D",strtotime($year."-".$month."-01"));
$weekArrNew = array_flip($weekArr);
$space = $weekArrNew[$firstDay];
return $space;
}
//获取当月有多少天:
function getMonthDays($month,$year=''){
if(!$year){
$year = date("Y");
}
for($i=28;$i<=32;$i++){
if(!checkdate($month,$i,$year)){
return $i-1;
break;
}
}
}
//打印日历:
function printRili($month,$year=''){
global $weekArr;
if(!$year){
$year = date("Y");
}
$space = getSpace($month,$year);
for($i=1;$i<=$space;$i++){
$weekArr[] = ' ';
}
$monthDays = getMonthDays($month,$year);
for($i=1;$i<=$monthDays;$i++){
$weekArr[] = $i;
}
//print_r($weekArr);
$returnStr = '
foreach($weekArr as $key=>$val){
if((($key+1) % 7 == 0) && $key!=0){
$returnStr .= '
'.$val.'';}else{
$returnStr.='
'.$val.'';}
}
$returnStr .= '
';return $returnStr;
}
//打印2012年3月份的日历:
echo printRili(3);
?>
td{
text-align:center;
}
.firststr{
background:orange;
font-weight:bold;
}
.strnum{
background:gray;
color:white;
}