月历表<?php $month = array(元月,一月,二月,三月,四月,五月,六月,七月,八月,九月,十月,十一月,十二月); $enmonth = array(元月,january ,february ,marcy ,april ,may ,june ,july ,august ,september ,october ,november ,december); $week = array(星期日,星期一,星期二,星期三,星期四,星期五,星期六); $backcolor = array(#ffc , #fff , #9f6 , #ffc , #6f0 , #6f6 , #f90 , #f06 , #f00 , #fc3 , #ff6 , #f99); function printmon($year, $mon) { date_default_timezone_set(asia/shanghai); global $month; global $enmonth; global $week; global $backcolor; $startdate =strtotime(1 $enmonth[$mon] $year); //获取查询的年月 $enddate = strtotime(+1 month,$startdate); //获取下一个月的开始日期作为月历输出的截止时间 $thedate = getdate($startdate); //把日期转化为字符串格式 $color = $backcolor[$mon]; //设置月历的背景颜色 echo(); $ym = $year . 年. $month[$mon]; echo($ym); echo(); for ($i=0; $i<7; $i++) //输出星期几 { echo(); echo($week[$i]); echo( ); } echo(
); $theweek = $thedate[wday];//判断当天是星期几 for ($i=0; $i<6; $i++) { echo(); for ($j=0; $j<7; $j++) { echo(); if ($startdate < $enddate && $theweek == $j)//把日期输出到对应的星期几所在列,并注意不要超出本月日期 { $theday = $thedate[mday]; echo($theday); $startdate = strtotime(+1 day, $startdate); //日期前移1天 $thedate = getdate($startdate);//更新日期 $theweek = ($theweek + 1) % 7;//更新星期 } echo( ); } echo(
); if ($startdate == $enddate) //如果已经输出全部日期,结束循环 { $i = 6; } } echo(请输入要查看的年号和月份(查询范围为1970年1月1日至2038年)年月= 1970 && $year = 1 && $month