首页 >php教程 >PHP源码 >php月历类

php月历类

PHP中文网
PHP中文网原创
2016-05-25 17:06:471256浏览

1. [文件] php月历类 

<meta charset="utf-8">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
<!--
$(function (){
   $(".subMenu").hide()
   $(".menu>td>a").mouseover(function () {
      $(".subMenu").stop(true,true).hide(0);
      $(this).parent().find("div.subMenu").slideDown("slow");
      $(this).parent().addClass("mainHover")
   })
   $(".menu>td").hover(function () {},function () {$(this).find("div.subMenu").hide();
        $(this).removeClass("mainHover")
      }
   )
})
-->
</script>
<style type="text/css">
<!--
#Layer1 {
   position:absolute;
   z-index:1;
        display:none; 
        width:100px; 
        height:100px; 
        background: #ccc;
        border:1px solid #ccc;
        padding: 10px;
        font-size: 14px;
        color: red;
        font-weight: bold;
}
a{
    display: block;
    width: 50px;
    height: 100%;
    text-decoration: none;
}
a:hover{
    text-decoration:underline;
}
-->
</style>
<?php 
class calendar{
    private $_BiaoJi=1;
    private $_CurrMon;//当前月
    private $_MonNum;//每月天数
    private $_WeekNum;//星期
    private $_url;//连接;
    private $_FirstDay;//每月的第一天
    private $_LastDay;//每月的最后一天
    private $_MonWeekSum;//每月有几个周
    //构造方法赋值
    function __construct() {
        $this->_CurrMon=  isset($_GET[&#39;mon&#39;])?$_GET[&#39;mon&#39;]:  date(&#39;n&#39;);
        $this->_MonNum=array(31,30,31,30,31,30,31,31,30,31,30,31);
        $this->_WeekNum=array(&#39;日&#39;,&#39;一&#39;,&#39;二&#39;,&#39;三&#39;,&#39;四&#39;,&#39;五&#39;,&#39;六&#39;);
        $this->_url=  $this->GetUrl();
        $this->_FirstDay=  getdate(mktime(0,0,0,  $this->_CurrMon,1,  date(&#39;Y&#39;)));
        $this->Two();
        $this->_LastDay=  $this->_MonNum[$this->_CurrMon-1];
        $this->_MonWeekSum=  $this->MonWeekSum();   
    }
    //返回连接
    private function GetUrl(){
        $_url=$_SERVER[&#39;REQUEST_URI&#39;];
        $_arr=  parse_url($_url);
        parse_str($_arr[&#39;query&#39;],$_QueryArr);
        unset($_QueryArr[&#39;mon&#39;]);
        $_str=  http_build_query($_QueryArr);
        return $_arr[&#39;path&#39;].&#39;?&#39;.$_str.&#39;&mon=&#39;;
    }
    //返回二月份天数
    private function Two(){
        if(date(&#39;L&#39;)){
            return $this->_MonNum[1]=29;
        }else{
            return $this->_MonNum[1]=28;
        }
    }
    //返回每月的星期数
    private function MonWeekSum(){
        return ceil(($this->_LastDay+$this->_FirstDay[&#39;wday&#39;])/7);
    }
    //上月
    private function PreMon(){
        if($this->_CurrMon>1){
            return "<a href=&#39;".$this->_url.($this->_CurrMon-1)."&#39; style=&#39;float:left; margin-left:15%;&#39;><<</a>";
        }
    }
    private function NextMon(){
        if($this->_CurrMon<12){
            return "<a href=&#39;".$this->_url.($this->_CurrMon+1)."&#39; style=&#39;float:right; margin-right:15%;&#39;>>></a>";
        }
    }
    //月历
    private function Mon(){
        echo "<table border=&#39;1&#39; align=&#39;center&#39; width=&#39;400&#39;>";
        echo "<tr><td colspan=&#39;7&#39; align=&#39;center&#39;>".$this->PreMon().&#39; &#39;.date("Y").&#39; 年 &#39;.$this->_CurrMon.&#39; 月 月历 &#39;.$this->NextMon()."</td></tr>";
        echo "<tr align=&#39;center&#39;>";
            foreach ($this->_WeekNum as $_arr1){
                echo "<td>{$_arr1}</td>";
            }
        echo "</tr>";
        for($i=0;$i<$this->_MonWeekSum;$i++){
            echo "<tr align=&#39;center&#39; class=&#39;menu&#39;>";
            for($j=0;$j<7;$j++){
                if($this->_FirstDay[&#39;wday&#39;]>0 || $this->_BiaoJi>$this->_LastDay){
                    echo "<td>&nbsp</td>";
                    $this->_FirstDay[&#39;wday&#39;]--;
                }else{
                    if($this->_BiaoJi==date(&#39;j&#39;)){
                      echo "<td style=&#39;background:red;&#39;><a href=&#39;#&#39;>{$this->_BiaoJi}</a><div id=&#39;Layer1&#39; class=&#39;subMenu&#39;>阳历".$this->_CurrMon."月".$this->_BiaoJi."号"."</div></td>";  
                    }else{
                      echo "<td><a href=&#39;#&#39;>{$this->_BiaoJi}</a><div id=&#39;Layer1&#39; class=&#39;subMenu&#39;>阳历".$this->_CurrMon."月".$this->_BiaoJi."号"."</div></td>";
                    }
                    $this->_BiaoJi++;
                }
            }
            echo "</tr>";
        }
        echo "</table>";
    }
    public function show(){
        if($this->_CurrMon>0 && $this->_CurrMon<=12){
            $this->Mon();
        }else{
            echo &#39;非法操作&#39;;
        }
    }
}
$_calendar=new calendar();
$_calendar->show();
?>

2. [文件] php月历类 ~ 70KB     

php月历类月历.zip


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn