PHP学习笔记之月历表

WBOY
Release: 2016-06-23 13:40:41
Original
1789 people have browsed it





月历表
  $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("");
 echo("");
 for ($i=0; $i  {
 echo("");
 }
 echo("");


 $theWeek = $theDate[wday];//判断当天是星期几
 for ($i=0; $i  {
 echo("");
 for ($j=0; $j  {
 echo("");
 }
 echo("");
 if ($startdate == $enddate) //如果已经输出全部日期,结束循环
 {
 $i = 6;
 }
 }
 
 echo("

$ym

");
 echo("

$WEEK[$i]

");
 echo("
");
 if ($startdate  {
 $theDay = $theDate[mday];
 echo("

$theDay

");
 $startdate = strtotime("+1 day", $startdate); //日期前移1天
 $theDate = getdate($startdate);//更新日期
 $theWeek = ($theWeek + 1) % 7;//更新星期
 }
 echo("
");
  }  
?>









请输入要查看的年号和月份(查询范围为1970年1月1日至2038年)







  $year = $_POST['myYear'];  
  $month = $_POST['myMonth'];
  if (is_numeric($year) && $year >= 1970 && $year   {
 if (is_numeric($month) && $month >= 1 && $month  {
 PrintMon($year, $month);
 }
 else if($month != NULL)
 {
 echo("月份不对" . "
");
 }
  }
  else if($year != NULL)
  {
 echo("年份不对" . "
");
  }
?>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!