简单实用PHP日历程序代码

作者:袖梨 2022-06-24

PHP日历程序,功能都是大众化的,可以下拉切换年月,上一年下一月下一年上一月,太另类的没去写,主要的写出来了,扩展起来就方便多了,标题为什么要叫精美呢,是因自已感觉界面还过得去,哈哈,让大家见笑了,不足之处还请指出。

效果代码如下

简单实用PHP日历程序代码

php日历核心代码

代码如下 复制代码

<?php
//日历类
class calendar {
//当前的年
private $year;
//当前的月
private $month;
//一个月中第一天是星期几
private $start_weekday;
//当前月的天数
private $days;
//最大数与最小年数,最大与最小月数
private $yearMonth = array(2080, 1900, 12, 1);
//构造函数
function __construct() {
if (isset($_GET['year'])) {
$this->year = $_GET['year'];
}
if (isset($_GET['month'])) {
$this->month = $_GET['month'];
}
$this->pnYm($this->year, $this->month);
$this->days = date('t', mktime(0, 0, 0, $this->month, 1, $this->year));
$this->start_weekday = date('w', mktime(0, 0, 0, $this->month, 1, $this->year));
$this->style();
}
//输出
private function style() {
echo '

foreach ($week as $val) {
echo '
'.$val.'
';
echo '';
echo 'select name="year" onchange="formaction()">';
for ($i = $this->yearMonth[1]; $i yearMonth[0]; $i++) {
if ($i == $this->year) {
echo ''.$i.'年';
}else {
echo ''.$i.'年';
}
}
echo '';
echo '';
for ($i = $this->yearMonth[3]; $i yearMonth[2]; $i++) {
if ($i == $this->month) {
echo ''.$i.'月';
}else {
echo ''.$i.'月';
}
}
echo '

echo '

'; //输出空格(当前一个月第一天前面要空出来的) for($i = 0; $i start_weekday; $i++) { echo ' '; } for ($k = 1; $k days; $k++) { $i++; if ($k == date('d')) { echo ''.$k.''; }else { echo ''.$k.''; } if ($i % 7 == 0) { if ($k != $this->days) { echo ' '; } } } echo '';
}
}
?>

html+css代码

代码如下 复制代码





PHP日历程序




<?php
require 'init.php';
$calendar = new calendar();
?>

相关文章

精彩推荐