上图是效果,刚学php,写个万年历玩玩~
php万年历 php万年历
"; echo"请输入正确年份!"; echo ""; return FALSE; } } if(!inputCheck()) { $year = date('Y');//获取当前年份 $month = date('m');//获取当前月份 $days = date('t',strtotime ( "$year-$month-1" ));//获取当前月份天数 $week = date('w',strtotime ( "$year-$month-1"));//获取当前星期 echo ""; echo " "; } else { @$year = $_GET['y'] ? $_GET['y'] : date('Y');//如果有GET方法传过来的参数就用get方法获得年份,如果没有就用当前年份 @$month = $_GET['m'] ? $_GET['m'] : date('m'); $days = date('t',strtotime ( "$year-$month-1" )); $week = date('w',strtotime ( "$year-$month-1")); echo "{$year}年{$month}月
"; echo ""; echo " "; } echo "{$year}年{$month}月
"; echo ""; echo " ";//下面的a标签 echo " ";//月份的下拉菜单 echo "";//画表 echo "
"; if($month==1)//判断上一月和下一月 { $preyear = $year -1; $premonth = 12; } else{ $preyear = $year; $premonth = $month - 1; } if($month == 12) { $nextyear = $year + 1; $nextmonth = 1; } else { $nextyear = $year; $nextmonth = $month + 1; } $last_year = $year - 1; $next_year = $year + 1; $nowyear = date('Y'); $nowmonth = date('m'); echo ""; echo " "; for ( $i = 1 - $week ; $i < $days ;) { echo "周日 "; echo "周一 "; echo "周二 "; echo "周三 "; echo "周四 "; echo "周五 "; echo "周六 "; echo ""; for( $j = 0 ; $j < 7 ; $j++) { if($i < 1 || $i > $days) { if($j % 2 == 0)//隔一行换个颜色 { echo " "; } echo ""; } else { echo " "; } } else { if($j %2 == 0) { if($year==date('Y')&&$month==date('m')&&$i==date('d'))//当前日期用蓝色标注 { echo " {$i} "; } else { echo "{$i} "; } } else { if($year==date('Y')&&$month==date('m')&&$i==date('d')) { echo "{$i} "; } else { echo "{$i} "; } } } $i++; } echo ""; ?>