PHP日历代码通用函数
程序员文章站
2024-01-09 08:44:22
...
//calendar.php
//Check if the month and year values exist
if ((!$_GET['month']) && (!$_GET['year'])) {
$month = date ("n");
$year = date ("Y");
} else {
$month = $_GET['month'];
$year = $_GET['year'];
}
//Calculate the viewed month
$timestamp = mktime (0, 0, 0, $month, 1, $year);
$monthname = date("F", $timestamp);
//Now let's create the table with the proper month
?>
Su
M
Tu
W
Th
F
Sa
$monthstart = date("w", $timestamp);
$lastday = date("d", mktime (0, 0, 0, $month + 1, 0, $year));
$startdate = -$monthstart;
//Figure out how many rows we need.
$numrows = ceil (((date("t",mktime (0, 0, 0, $month + 1, 0, $year)) + $monthstart) / 7));
//Let's make an appropriate number of rows...
for ($k = 1; $k ?>
//Use 7 columns (for 7 days)...
for ($i = 0; $i $startdate++;
if (($startdate $lastday)){
//If we have a blank day in the calendar.
?>
} else {
if ($startdate == date("j") && $month == date("n") && $year == date("Y")){
?>',event);" >
} else {
?>',event);" >
}
}
}
?>
}
?>