您好,欢迎访问一九零五行业门户网

简单实用PHP日历程序代码

日历程序代码我们一般会使用一些js插件来实现了,但是像博客这种日志分类我们会使用php程序来实现,下面一聚教程小编就来为你介绍一下吧。
php日历程序,功能都是大众化的,可以下拉切换年月,上一年下一月下一年上一月,太另类的没去写,主要的写出来了,扩展起来就方便多了,标题为什么要叫精美呢,是因自已感觉界面还过得去,哈哈,让大家见笑了,不足之处还请指出。
效果代码如下
php日历核心代码
 代码如下 复制代码
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 '
';
        $this->weeklist();
        $this->daylist();
        echo '';
    }
    //年月参数判断
    private function ymcheck($year, $month) {
        if (!is_numeric($year)) {
            $year = date('y');
        }
        if (!is_numeric($month)) {
            $month = date('m');
        }
        if ($month yearmonth[3]) {
            $month = $this->yearmonth[2];
            $year -= 1;
        }
        if ($month > $this->yearmonth[2]) {
            $month = $this->yearmonth[3];
            $year = intval($year) + 1;
        }
        $year = $year yearmonth[1] ? $this->yearmonth[1] : $year;
        $year = $year > $this->yearmonth[0] ? $this->yearmonth[0] : $year;
        return array($year, $month);
    }
    //上一年、下一年、上一月、下一月
    private function pnym($year, $month) {
        $ym = $this->ymcheck($year, $month);
        $this->year = $ym[0];
        $this->month = $ym[1];
    }
    //weeklist周列表
    private function weeklist() {
        $week = array('日','一','二','三','四','五','六');
        echo '';
        foreach ($week as $val) {
            echo ''.$val.'';
        }
        echo '
';
    }
    //daylist天列表
    private function daylist() {
        //年月日导航
        echo '';
        echo 'year-1).'&month='.%24this->month.'> ';
        echo 'year.'&month='.(%24this->month-1).'> ';
        echo '';
        echo '';
        echo '';
        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 'year.'&month='.(%24this->month+1).'>> ';
       echo 'year+1).'&month='.%24this->month.'>>> ';
       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日历程序
其它类似信息

推荐信息