PHP万年历实现代码
使用服务器端编程语言(专业超文本预处理器的缩写)实现万年历功能的要点: •得到当前要处理的月份总共有多少天$天得到当前要处理的月份的一号是星期几$ dayofweek $天的作用:知道要处理的月份共有多少天,就可以通过循环输出天数了$dayofweek的作用:只有知道每个月的一号是星期几,才能知道在输出天数之前需要输出多少空格(空白)最终效果图如下
"万年历类"的代码如下:复制代码代码如下:php /** * PHP万年历* @作者fly 2012/10/16 */class Calendar { protected $ _ table;//表格表格受保护的$ _ currentDate//当前日期受保护的$ _年;//年受保护的$ _月;//月受保护的$ _天;//给定的月份应有的天数受保护的$ _ dayofweek//给定月份的一号是星期几/** * 构造函数*/public function _ _ construct(){ $ this-_ table=' ';$this-_year=isset($_GET['y'])?$ _ GET[' Y ']:日期(' Y ');$this-_month=isset($_GET['m'])?$ _ GET[' m ']: date(' m ');if ($this-_month12){//处理出现月份大于12的情况$ this-_ month=1;$今年-_年;} if ($this-_month1){//处理出现月份小于一的情况$ this-_ month=12;$今年-_年-;} $ this-_当前日期=$ this-_年.'年。$本月-_。'月份;//当前得到的日期信息$this-_days=date('t ',mktime(0,0,0,$this-_month,1,$ this-_ year));//得到给定的月份应有的天数$this-_dayofweek=date('w ',mktime(0,0,0,$this-_month,1,$ this-_ year));//得到给定的月份的一号是星期几} /** * 输出标题和表头信息*/protected function _ show title(){ $ this-_ table=' table ' table head tr align=' center ' th col span=' 7 ' ' .$this-_currentDate ./th/tr/the ad ';$这个-_表=' tbodytr$ this-_表='td style='color:red '星期日/TD ';$这个-_表='td .星期一/TD ';$这个-_表='td .星期二/TD ';$这个-_表='td .星期三/TD ';$这个-_表='td .星期四/TD ';$这个-_表='td .星期五/TD ';$这个-_表='td style='color:red '星期六/TD ';$这个-_表='/tr ';} /** * 输出日期信息* 根据当前日期输出日期信息*/protected function _ show date(){ $ nums=$ this-_ dayofweek 1;for($ I=1;$ I=$ this-_ dayofweek;$i ){//输出一号之前的空白日期$这个-_表=' TD nbsp/TD ';} for($ I=1;$ I=$ this-_ days;$i ){//输出天数信息if ($nums%7==0){//换行处理:7个一行$这个-_表=' TD $ I/TD/trtr ';}else{ $this-_table .=' TD $ I/TD ';} $ nums} $this-_table .='/t正文/表格';$这个-_表='h3a href='?y=' .($今年-_年)。m=' .($本月-1日).''上一月/a ';$这个-_表='a href='?y=' .($今年-_年)。m=' .($本月1日)'下一月/a/H3 ';} /** * 输出日历*/public函数show calendar(){ $ this-_ show title();$ this-_ show date();echo $ this-_ table;} } $ calc=新日历();$ calc-showCalendar();出处:http://www .cn博客。com/洪飞
版权声明:PHP万年历实现代码是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。