国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

PHP萬年歷實現程序代碼

2024-05-04 21:58:17
字體:
來源:轉載
供稿:網友

使用PHP實現萬年歷功能的要點:

得到當前要處理的月份總共有多少天$days,得到當前要處理的月份的一號是星期幾$dayofweek,$days的作用:知道要處理的月份共有多少天,就可以通過循環(huán)輸出天數了,$dayofweek的作用:只有知道每個月的1號是星期幾,才能知道在輸出天數之前需要輸出多少空格(空白).

PHP完整實例代碼如下:

  1. <?php 
  2. /** 
  3.  * PHP萬年歷 
  4.  * @author Fly 2012/10/16 
  5.  */ 
  6. class Calendar{ 
  7.     protected $_table;//table表格 
  8.     protected $_currentDate;//當前日期 
  9.     protected $_year;    //年 
  10.     protected $_month;    //月 
  11.     protected $_days;    //給定的月份應有的天數 
  12.     protected $_dayofweek;//給定月份的 1號 是星期幾 
  13.     /** 
  14.      * 構造函數 
  15.      */ 
  16.     public function __construct()  
  17.     { 
  18.         $this->_table=""
  19.         $this->_year  = isset($_GET["y"])?$_GET["y"]:date("Y"); 
  20.         $this->_month = isset($_GET["m"])?$_GET["m"]:date("m"); 
  21.         if ($this->_month>12){//處理出現月份大于12的情況 
  22.             $this->_month=1; 
  23.             $this->_year++; 
  24.         } 
  25.         if ($this->_month<1){//處理出現月份小于1的情況 
  26.             $this->_month=12; 
  27.             $this->_year--; 
  28.         } 
  29.         $this->_currentDate = $this->_year.'年'.$this->_month.'月份';//當前得到的日期信息 
  30.         $this->_days           = date("t",mktime(0,0,0,$this->_month,1,$this->_year));//得到給定的月份應有的天數 
  31.         $this->_dayofweek    = date("w",mktime(0,0,0,$this->_month,1,$this->_year));//得到給定的月份的 1號 是星期幾 
  32.     } 
  33.     /** 
  34.      * 輸出標題和表頭信息 
  35.      */ 
  36.     protected function _showTitle() 
  37.     { 
  38.         $this->_table="<table><thead><tr align='center'><th colspan='7'>".$this->_currentDate."</th></tr></thead>"
  39.         $this->_table.="<tbody><tr>"
  40.         $this->_table .="<td style='color:red'>星期日</td>"
  41.         $this->_table .="<td>星期一</td>"
  42.         $this->_table .="<td>星期二</td>"
  43.         $this->_table .="<td>星期三</td>"
  44.         $this->_table .="<td>星期四</td>"
  45.         $this->_table .="<td>星期五</td>"
  46.         $this->_table .="<td style='color:red'>星期六</td>"
  47.         $this->_table.="</tr>"
  48.     } 
  49.     /** 
  50.      * 輸出日期信息 
  51.      * 根據當前日期輸出日期信息 
  52.      */ 
  53.     protected function _showDate() 
  54.     { 
  55.         $nums=$this->_dayofweek+1; 
  56.         for ($i=1;$i<=$this->_dayofweek;$i++){//輸出1號之前的空白日期 
  57.             $this->_table.="<td>&nbsp</td>"
  58.         } 
  59.         for ($i=1;$i<=$this->_days;$i++){//輸出天數信息 
  60.             if ($nums%7==0){//換行處理:7個一行 
  61.                 $this->_table.="<td>$i</td></tr><tr>";     
  62.             }else
  63.                 $this->_table.="<td>$i</td>"
  64.             } 
  65.             $nums++; 
  66.         } 
  67.         $this->_table.="</tbody></table>"
  68.         $this->_table.="<h3><a href='?y=".($this->_year)."&m=".($this->_month-1)."'>上一月</a>&nbsp;&nbsp;&nbsp;"
  69.         $this->_table.="<a href='?y=".($this->_year)."&m=".($this->_month+1)."'>下一月</a></h3>"
  70.     } 
  71.     /** 
  72.      * 輸出日歷 
  73.      */ 
  74.     public function showCalendar() 
  75.     { 
  76.         $this->_showTitle(); 
  77.         $this->_showDate(); 
  78.         echo $this->_table; 
  79.     } 
  80. $calc=new Calendar(); 
  81. $calc->showCalendar(); 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 永顺县| 霍城县| 武隆县| 华容县| 西和县| 贵港市| 板桥市| 保康县| 新竹市| 海兴县| 教育| 道真| 通渭县| 滕州市| 海伦市| 竹北市| 宁津县| 安图县| 扎囊县| 普兰店市| 保德县| 噶尔县| 波密县| 子洲县| 黎城县| 鹤岗市| 禹城市| 海安县| 靖江市| 油尖旺区| 积石山| 伊川县| 望都县| 怀远县| 巴林左旗| 西畴县| 宝兴县| 景东| 海丰县| 炉霍县| 柳江县|