//获得日历数组
function getCal($y = 0, $m = 0) {
if (!$m || !$y) {
$days = date("t");
$m = date("n");
$y = date("Y");
} else {
$days = date("t", strtotime("$y-$m-1"));
}
$cal = array(array('日', '一', '二', '三', '四', '五', '六'));
$o_week = array(0 => "", 1 => "", 2 => "", 3 => "", 4 => "", 5 => "", 6 => "");
$week = array(0 => "", 1 => "", 2 => "", 3 => "", 4 => "", 5 => "", 6 => "");
$tody = date('j');
for ($j = 1; $j <= $days; $j++) {
$w = date('w', strtotime("$y-$m-$j"));
$week[$w] = $j;
if ($w == 6 || $j == $days) {
$cal[] = $week;
$week = $o_week;
}
}
return $cal;
}
//生产日历表格
function createCal($calName = "cal", $return = false) {
$y = isset($_REQUEST['y']) ? $_REQUEST['y'] : date("Y");
$m = isset($_REQUEST['m']) ? $_REQUEST['m'] : date("n");
$calName = isset($_REQUEST['cn']) ? $_REQUEST['cn'] : $calName;
$j = date("j");
$cal = getCal($y, $m);
$calstr = "";
$tdi = '
%s';$td = '
%s';foreach ($cal as $k => $w) {
$calstr .= "
";foreach ($w as $d) {
if ($d && $k != 0
&& strtotime("$y-$m-$d") >= strtotime(date("Y-n-j"))) {
$clss = (strtotime("$y-$m-$d") == strtotime(date("Y-n-j"))) ? "now"
: "";
$calstr .= sprintf($tdi, $clss, $calName, $d, $d, $d);
} else {
$calstr .= sprintf($td, $d);
}
}
$calstr .= "
";}
if ($return) {
return $calstr;
} else {
die($calstr);
}
}
echo createCal();