第二节 PHP 实现日历功能
最后更新于:2022-04-02 01:46:57
>[success] # PHP 实现日历功能
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/bb1b932d357938a48ae6c4a241b574e0_505x243.png)
~~~php
//show_calendar.php
12) {
$month = 1;
$year++;
} elseif ($month < 0) {
$month = 12;
$year--;
}
$t = strtotime("$year-$month-1");
$last = date('t', strtotime('-1 month', $t));
$start = date('w', $t) ? range($last - date('w', $t) + 1, $last) : range($last - 6, $last);
$days = range(1, date('t', $t));
$end = range(1, 6 * 7 - count($start) - count($days));
$daytable = "";
$w = 1;
for ($i = 0; $i < count($start); $i++) {
if ($w % 7 == 0) {
$daytable .= "$start[$i] ";
} else {
$daytable .= "$start[$i] ";
}
$w++;
}
for ($i = 0; $i < count($days); $i++) {
if ($w % 7 == 0) {
$daytable .= "$days[$i] ";
} else {
$daytable .= "$days[$i] ";
}
$w++;
}
for ($i = 0; $i < count($end); $i++) {
if ($w % 7 == 0) {
$daytable .= "$end[$i] ";
} else {
$daytable .= "$end[$i] ";
}
$w++;
}
$daytable .= " ";
?>
~~~
';
上一月 | 年月份 | 下一月 | ||||
---|---|---|---|---|---|---|
星期日 | 星期一 | 星期二 | 星期三 | 星期四 | 星期五 | 星期六 |