当前位置:Gxlcms > PHP教程 > php自动生成月历的代码

php自动生成月历的代码

时间:2021-07-01 10:21:17 帮助过:17人阅读

  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<=5;$a++){
  31. print("
  32. ");
  33. $diffDays = $firstDay-$lastDay;
  34. if($firstDay>$lastDay && $currentDays ==1 && ($diffDays<>1)){
  35. for($x=$lastDay;$x>=0;$x--){
  36. $printDays = $days-$x;
  37. print("
  38. ");
  39. }
  40. for($z=1;$z<$firstDay-$lastDay;$z++){
  41. print("
  42. ");
  43. }
  44. for($y=$firstDay;$y<7;$y++){
  45. print("
  46. ");
  47. $currentDays++;
  48. }
  49. } elseif($firstDay!=0 && $currentDays==1){
  50. for($z=1;$z<=$firstDay;$z++){
  51. print("
  52. ");
  53. }
  54. for($y=$firstDay;$y<7;$y++){
  55. print("
  56. ");
  57. $currentDays++;
  58. }
  59. } else {
  60. for($u=1;$u<=7 && $currentDays<=$days;$u++){
  61. print("
  62. ");
  63. $currentDays++;
  64. }
  65. }
  66. print("
  67. ");
  68. }
  69. print("
  70. P".strftime("%b %Y",mktime (0,0,0,$MM,1,$YYYY))."N
    SunMonTueWedThuFriSat
    $printDays $currentDays $currentDays$currentDays
    ");
  71. }
  72. }
  73. ?>

人气教程排行