首页 > 作文

php实现的日历程序

更新时间:2023-04-06 18:19:59 阅读: 评论:0

本文实例讲述了php实现的日历程序。分享给大家供大家参考。具体如下:

<?php////判断$year和$month是否为空,如果为空就获取系统当前日期,否则用$_get获取$year = empty($_get['year']) ? date("y"): $_get["year"];$month = empty($_get['month']) ? date("m"): $_get["month"];////获取当前日期////$today = date("ymj");////初始化日期数组////$maxday = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");$maxday_count = count($maxday);////初始化星期数组////$weekday = array("<font color='red'>sun</font>","mon","tue","wed","thu","fri","<font color='red'>sat</font>");$weekday_count = count($weekday);$daynum = 0;$space = "<td></td>";$col = 0;////打印表格头部////?><form action="calendar.php" method="post" name="linked"><table><tr><td colspan=3 align=center><a href="?year=<?php if($year-1 > 1900)echo $year-1;el echo $year;?>&month=<?php echo $month?>" onclick="javascript:document.linked.submit();" name="year"><<</a><?php echo $year?><a href="?year=<?php if($year+1 <2999) echo $year+1;el echo $year;?>&month=<?php echo $month?>" onclick="javascript:document.linked.submit();" name="year">>></a></td><td></td><td colspan=3 align=center><a href="?year=<?php echo $year?>&month=<?php if($month-1 >0) if($month-1 < 10)echo "0".($month-1电子狗哪个牌子好); el echo $month-1; el echo $month;?>" onclick="javascript:document.linked.submit();" name="month"><<</a><?php echo $month;?><a href="?year=<?php echo $year?>&month=<?php if($month+1 <13) if($month+1 <10) echo "0".($month+1);el echo ($month+1); el echo $month;?>" onclick="javascript:document.li建行手机银行费用nked.submit();" name="month">>></a></td></tr><tr><td colspan="8"></td></tr><tr><?php////打印星期列表////while(list(,$weekvalue) = each($weekday)) echo "<td align=center>".$weekvalue."</td>";echo "</tr>";////打印日期列表//////当月份为4,6,9,11的时候,从数组末尾删除一个值,也就是删除31这个值.if($month == 4 or $month == 6 or $month == 9 or $month == 11){ array_pop($maxday); $maxday_count--;}//先判断月份是否为2月,如果是的话再判断年份是否为闰年,如果是的话就从数组尾部移除2个值,否则就移除3个值.if($month == 2){ if($year % 4 == 0) { array_pop($包容的故事maxday); array_pop($maxday); $maxday_count-=2; } el { array_pop($maxday); array_pop($maxday); array_pop($maxday); $maxday_count-=3; }}////打印日期////w运动会横幅hile($daynum < $maxday_count){echo "<tr>"; while(list($colnum,$dayvalue) = each($maxday)) {  //判断当前日期为一星期中的哪一天  $dayweek = date("w",strtotime($year."-".$month."-".$dayvalue));  //当当前日期处于第1个,也就是每个月的第1天的时候,在它前面补上相应的空格子  if($dayvalue == 1)   for($i=0;$i<$dayweek;$i++)   echo $space;//打印每个月空出的几个格子  $daynum++;  //当打印日期的时候与当前日期字符串进行比较,如果相等就将字体标为红色.  if($year.$month.$dayvalue == $today余尝谓读书有三到)  {   $u1 = "<b><u>";   $u2 = "</b></u>";  }  el  {   $u1 = "";   $u2 = "";  }  if($dayweek == 0 or $dayweek == 6)   $color = "red";  el   $color = "black";  echo "<td align=center><font color=".$color.">".$u1.$dayvalue.$u2."</font></td>";  //用本周第几天这个值加1,如果是7的倍数就换行退出此轮循环(换行打印)  if(($dayweek+1) % 7 == 0)  {   $col++;   break;  } }echo "</tr>";}?>

运行效果如下:

希望本文所述对大家的php程序设计有所帮助。

本文发布于:2023-04-06 18:19:57,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/08d6d62884475ba3fcfae9960774efaf.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:php实现的日历程序.doc

本文 PDF 下载地址:php实现的日历程序.pdf

标签:日期   数组   星期   每个月
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图