PHP实现简单日历类编写
用PHP实现日历类的编写,供大家参考,具体内容如下
calendar.class.php
year=isset($_GET['year'])?$_GET['year']:date("Y"); $this->month=isset($_GET["month"])?$_GET["month"]:date("m"); $this->first_week=date("w",mktime(0,0,0,$this->month,1,$this->year)); $this->day=date("t",mktime(0,0,0,$this->month,1,$this->year)); } functionshowCalendar(){ //echo$this->year."年".$this->month."月".$this->first_week."天".$this->day; echo"";//用表格输出 $this->chageDate("index.php");//用于用户调整年月份 $this->weekList();//显示星期 $this->dayList();//显示天数 echo""; } //1、显示星期 privatefunctionweekList(){ $week=array("日","一","二","三","四","五","六"); echo" "; for($i=0;$i "; } //2.显示天数 privatefunctiondayList(){ $color="#2ca50c"; echo"".$week[$i].""; } echo" "; for($i=0;$i<$this->first_week;$i++){//输出空格,弥补当前月空缺部分 echo" "; } for($k=1;$i<=$this->day;$k++){ $i++; if($k==date("d"))echo" ".$k."";//是今天,加效果 elseecho" ".$k.""; if($i%7==0){ echo" ";//每7天一次换行 if($i%2==0)$color="#2ca50c"; else$color="#9ddb27";//实现各行换色的效果 } } while($i%7!=0){//将剩余的空格补完 echo" "; } //3、用于用户调整天数 privatefunctionchageDate($url="index.php"){ echo""; $i++; } echo" "; echo" "; echo""; echo" ".$this->year."年".$this->month."月
"; echo" "; } privatefunctionprevYear($year,$month){//获取上一年的数据 $year--; if($year<1970)$year=1970; return"year={$year}&month={$month}"; } privatefunctionprevMonth($year,$month){ if($month==1){ $year--; if($year<1970)$year=1970; $month=12; }else$month--; return"year={$year}&month={$month}"; } privatefunctionnextYear($year,$month){//获取上一年的数据 $year++; if($year>2038)$year=2038; return"year={$year}&month={$month}"; } privatefunctionnextMonth($year,$month){ if($month==12){ $year++; if($year>2038)$year=2038; $month=1; }else$month++; return"year={$year}&month={$month}"; } }"." prevYear($this->year,$this->month)."'>"."<".""; echo" "." "; echo"prevMonth($this->year,$this->month)."'>"."<<".""; echo" "; echo'"; echo' year.'&month=\'+this.options[selectedIndex].value">'; for($month=1;$month<=12;$month++){ $selected1=($month==$this->month)?"selected":""; echo''; } echo''; echo" "." nextMonth($this->year,$this->month)."'>".">>".""; echo" "." nextYear($this->year,$this->month)."'>".">".""; echo"
主页index.php
日历显示 showCalendar(); ?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。