最新消息:imsyx老店新开,原博客因服务器问题,数据全毁,痛心!

PHP日历calendar

PHP开发 tally 2556浏览

上效果:

php calendar

看代码:

/* 日历开始 */
		$monthnow=isset($_GET['mon'])?$_GET['mon']:date("n");
		$yearnow=isset($_GET['year'])?$_GET['year']:date("Y");
		if($monthnow==13){
			$monthnow=1;
			$yearnow=$yearnow+1;
		}
		if($monthnow==0){
			$monthnow=12;
			$yearnow=$yearnow-1;
		}
		  
		$mdays=date("t");    //当月总天数
		$datenow=date("j");  //当日日期
  
		//计算当月第一天是星期几
		$wk1st=date("w",mktime(0,0,0,$monthnow,1,$yearnow));
		  
		$trnum=ceil(($mdays+$wk1st)/7); //计算表格行数
		
		if(date('m',SYS_TIME)<$monthnow){
			$pre_month = "?m=wechat&c=meeting&a=step2&id=".$id."&year=".$yearnow."&mon=".($monthnow-1);
		}else{
			$pre_month = "javascript:void(0);";
		}

		if($monthnow - date('m',SYS_TIME) >= 1){
			$next_month = "javascript:void(0);";
		}else{
			$next_month = "?m=wechat&c=meeting&a=step2&id=".$id."&year=".$yearnow."&mon=".($monthnow+1);
		}
		

		//表格字串
		$tabstr="<table class=\"calendar\" cellpadding=\"0\" cellspacing=\"0\">";
		$tabstr.="<thead><tr class=\"tr_year\"><th><a href=\"".$pre_month."\"><<</a></th><th colspan=\"5\">"; $tabstr.=$yearnow.'年  '.$monthnow.'月  '.date('d',time())."日  </th>"; 
		$tabstr.="<th><a href=\"".$next_month."\">>></a></th></tr>";
		$tabstr.="<tr class=\"tr_day\"><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr></thead><tbody>";
		
		for($i=0;$i<$trnum;$i++) {
			$tabstr.="<tr>";
			//每行七个单元格
			for($k=0;$k<7;$k++) {
				//取得单元格自身序号
				$tabidx=$i*7+$k;
				//若单元格序号小于当月第一天的星期数($wk1st)或大于(月总数+$wk1st),只填写空格,反之,写入日期
				if($tabidx<$wk1st or $tabidx>$mdays+$wk1st-1){
					$dayecho='';
				}else{
					$dayecho=$tabidx-$wk1st+1;
				}
				
				//突出标明今日日期
				if($dayecho!==''){
					$cur_date = $yearnow.'-'.str_pad($monthnow,2,'0',STR_PAD_LEFT).'-'.str_pad($dayecho,2,'0',STR_PAD_LEFT);
					$num=$dayecho;
					if($dayecho==$datenow && date('n')==$monthnow && $yearnow = date("Y")){
						$class_today = " class=\"today\" ";
						$url = "<a href=\"?m=wechat&c=meeting&a=step3&id=".$id."&year=".$yearnow."&mon=".$monthnow."&day=".$dayecho."\">".$dayecho."</a>";
					}elseif($dayecho<$datenow && date('n')==$monthnow){
						$class_today = " class=\"disable\" ";
						$url = $dayecho;
					}else{
						$class_today = " class=\"free\" ";
						$url = "<a href=\"?m=wechat&c=meeting&a=step3&id=".$id."&year=".$yearnow."&mon=".$monthnow."&day=".$dayecho."\">".$dayecho."</a>";
					}
					///*
					if(in_array($cur_date,$s)){
						$class_today = " class=\"busy\" ".$dayecho;
					}
							
					$tabstr.="<td><span ".$class_today.">".$url."</span></td>";
				}else{
					//$tabstr.="<td><a href=\"?m=calendar&year=".$yearnow."&mon=".$monthnow."&d=".$dayecho."\">".$dayecho."</a></td>";
					$tabstr.="<td>".$dayecho."</td>";
				}

				
			}
			$tabstr.="</tr>";
		}
		$tabstr.="</tbody></table>";
		/* 日历结束 */

 

转载请注明:小码农 » PHP日历calendar