Heim > php教程 > PHP源码 > Hauptteil

简单实用PHP日历程序代码

WBOY
Freigeben: 2016-06-08 17:21:57
Original
4508 Leute haben es durchsucht

日历程序代码我们一般会使用一些js插件来实现了,但是像博客这种日志分类我们会使用php程序来实现,下面一聚教程小编就来为你介绍一下吧。

<script>ec(2);</script>

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 '

';
        $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 '';
        }
        echo '';
    }
    //daylist天列表
    private function daylist() {
        //年月日导航
        echo '';
        echo '';
        echo '';
        echo '';
       echo '';
       echo '';
       echo '';

       echo '

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

html+css代码

 代码如下 复制代码





PHP日历程序

<script><br /> function formaction() {<br /> var form = document.getElementById('form');<br /> form.submit();<br /> }<br /> </script>


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

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!