首页 >后端开发 >php教程 >php自动生成月历的代码

php自动生成月历的代码

WBOY
WBOY原创
2016-07-25 09:04:071036浏览
  1. /**
  2. php自动生成月历
  3. link:bbs.it-home.org 2013-3-7
  4. */
  5. function calendar($MM,$YYYY){
  6. if($MM=="") $MM = date("m");
  7. if($YYYY=="") $YYYY = date("Y");
  8. if(checkdate($MM,1,$YYYY)){
  9. $stringDate = strftime("%d %b %Y",mktime (0,0,0,$MM,1,$YYYY));
  10. $days = strftime("%d",mktime (0,0,0,$MM+1,0,$YYYY));
  11. $firstDay = strftime("%w",mktime (0,0,0,$MM,1,$YYYY));
  12. $lastDay = strftime("%w",mktime (0,0,0,$MM,$days,$YYYY));
  13. $PRintDays = $days;
  14. $preMonth = strftime("%m",mktime (0,0,0,$MM-1,1,$YYYY));
  15. $preYear = strftime("%Y",mktime (0,0,0,$MM-1,1,$YYYY));
  16. $nextMonth = strftime("%m",mktime (0,0,0,$MM+1,1,$YYYY));
  17. $nextYear = strftime("%Y",mktime (0,0,0,$MM+1,1,$YYYY));
  18. print("");
  19. print("
  20. ");
  21. print("
  22. ");
  23. print("
  24. ");
  25. print("
  26. ");
  27. print("
  28. ");
  29. $currentDays = 1;
  30. for($a=1;$a print("
  31. ");
  32. $diffDays = $firstDay-$lastDay;
  33. if($firstDay>$lastDay && $currentDays ==1 && ($diffDays1)){
  34. for($x=$lastDay;$x>=0;$x--){
  35. $printDays = $days-$x;
  36. print("
  37. ");
  38. }
  39. for($z=1;$z print("
  40. ");
  41. }
  42. for($y=$firstDay;$y print("
  43. ");
  44. $currentDays++;
  45. }
  46. } elseif($firstDay!=0 && $currentDays==1){
  47. for($z=1;$z print("
  48. ");
  49. }
  50. for($y=$firstDay;$y print("
  51. ");
  52. $currentDays++;
  53. }
  54. } else {
  55. for($u=1;$u print("
  56. ");
  57. $currentDays++;
  58. }
  59. }
  60. print("
  61. ");
  62. }
  63. print("
  64. P".strftime("%b %Y",mktime (0,0,0,$MM,1,$YYYY))." N
    Sun Mon Tue Wed Thu Fri Sat
    $printDays   $currentDays   $currentDays $currentDays
    ");
  65. }
  66. }
  67. ?>
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn