search
Homephp教程PHP源码php简单的日历程序

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

class Calendar{
   /**
    * @desc       :简单的日历类,供大家学习
    * @author     :Allen Wu
    * @Email      :wukewei00o@126.com
    * @Date       :2008-09-12
    * @version    :v1.0
    */
    /*定义变量年、月、日*/
    private $year,$month,$day;
    /*定义数组星期并初始化*/
    private $week    = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
    /*定义数组月份并初始化*/
    private $monthes = array("01"=>"一月",
                             "02"=>"二月",
                             "03"=>"三月",
                             "04"=>"四月",
                             "05"=>"五月",
                             "06"=>"六月",
                             "07"=>"七月",
                             "08"=>"八月",
                             "09"=>"九月",
                             "10"=>"十月",
                             "11"=>"十一月",
                             "12"=>"十二月"
                             );

    function __construct(){
        $year  = isset($_POST['year']) ? $_POST['year'] : date('Y');
        $month = isset($_POST['month']) ? $_POST['month'] : date('m');
        $day   = isset($_POST['day']) ? $_POST['day'] : date('d');
        $this->set($year, $month, $day);
    }
    /**
     * @desc   设置年、月、日的值
     * @params String $year
     * @params String $month
     * @params String $day
     * @return
     */
    private function set($year, $month, $day){
        $this->year  = $year;
        $this->month = $month;
        $this->day   = $day;
    }

    /**
     * @desc   获取年、月、日的值并以数组形式返回
     * @params Array $info
     * @retrun Array
     */
    function get(array $info){
        $info = array('year' => $this->year,
                      'month'=> $this->month,
                      'day'  => $this->day);
        return $info;
    }
    /**
     * @desc   获得指定日期的星期值
     * @params String $year
     * @params String $month
     * @params String $day
     * @return String
     */
    private function getWeek($year, $month, $day){
        $weekday = date("w",mktime(0,0,0,$month,$day,$year));
        return $weekday;
    }
 

    /**
     * 输出日历,有兴趣的可以改进!
     * 其实这不是一个方法,不希望在类里出现html和样式
     * 有兴趣的可以改进下!给大家起个抛砖引玉的作用
     *
     */
    public function out(){
        $firstDay = $this->getWeek($this->year, $this->month, 1);
        echo "
".
             "
".
             "
";

        /*打印星期标头*/
        for($week = 0; $week week); $week++){
            echo "";      //补充打印
                for($i = 0; $i                     echo "
".$this->week[$week];
        }

        /*打印所有日期*/
        for($tmpd = 1; $tmpd month,$this->day,$this->year)); $tmpd++){
            if(strcmp($tmpd, $this->day) == 0){   //获得当前日期,做标记
                $flag="bgcolor='#ff0000'";
            }else{
                $flag=" bgcolor='#ffffff'";
            }
            if($tmpd == 1){
                echo "
";
                }
            }
            if(strcmp($this->getWeek($this->year, $this->month, $tmpd), 0) == 0){
                echo "
$tmpd";
            }else{
                echo "
$tmpd";
            }
        }
        echo "
";
    }
}
$obj = new Calendar();
$obj->out();
?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.