欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php自动生成月历的代码

程序员文章站 2022-05-16 20:20:04
...
  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. ?>
复制代码