Home > Backend Development > PHP Tutorial > PHP automatically generates monthly calendar code

PHP automatically generates monthly calendar code

WBOY
Release: 2016-07-25 09:04:07
Original
1034 people have browsed it
  1. /**
  2. php automatically generates monthly calendar
  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. ?>
复制代码


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