Home > Backend Development > PHP Tutorial > PHP calendar code sharing simple and practical PHP calendar code

PHP calendar code sharing simple and practical PHP calendar code

WBOY
Release: 2016-07-25 08:56:09
Original
2940 people have browsed it
  1. header("content-type:text/html;charset=utf-8");
  2. ?>
  3. /**
  4. * Simple and practical php calendar code
  5. * edit: bbs.it-home.org
  6. */
  7. if(!emptyempty($_GET)){
  8. $year = $_GET['year'];
  9. $month = $_GET['month'];
  10. }
  11. if(emptyempty($year)){
  12. $year = date('Y');
  13. }
  14. if(emptyempty($month)){
  15. $month = date('m');
  16. }
  17. $start_weekday = date('w',mktime(0,0,0,$month,1,$year));
  18. //echo $start_weekday;
  19. $days = date('t',mktime(0,0,0,$month,1,$year));
  20. //echo $days;
  21. $week = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
  22. $i = 0;
  23. $k = 1;
  24. $j = 0;
  25. echo '';
  26. echo '
  27. ';
  28. echo '
  29. ';
  30. for($i = 0;$i < 7;$i++){
  31. echo '
  32. ';
  33. }
  34. echo '
  35. ';
  36. echo '
  37. ';
  38. for($j = 0;$j < $start_weekday;$j++){
  39. echo '
  40. ';
  41. }
  42. while($k <= $days){
  43. if($k == date('d')){
  44. echo '
  45. ';
  46. }else{
  47. echo '
  48. ';
  49. }
  50. if(($j+1) % 7 == 0){
  51. echo '
  52. ';
  53. }
  54. $j++;
  55. $k++;
  56. }
  57. while($j % 7 != 0){
  58. echo '
  59. ';
  60. $j++;
  61. }
  62. echo '
  63. ';
  64. echo '
  65. ';
  66. echo "
  67. ';
  68. echo "
  69. ';
  70. echo '
  71. ';
  72. echo "
  73. ';
  74. echo "
  75. ';
  76. echo '
  77. ';
  78. echo '
  79. '.$year.'年'.$month.'月'.'
    '.$week[$i].'
    '.$j.' '.$k.' '.$k.'
    '.$j.'
    ".'<<'.' ".'<'.' ';
  80. echo '
    ';
  81. echo ''.'年';
  82. echo '';
  83. echo '月';
  84. echo '';
  85. echo '';
  86. echo '
  87. ".'>>'.' ".'>'.'
    ';
  88. function lastYear($year,$month){
  89. $year = $year-1;
  90. return "year=$year&month=$month";
  91. }
  92. function lastMonth($year,$month){
  93. if($month == 1){
  94. $year = $year -1;
  95. $month = 12;
  96. }else{
  97. $month--;
  98. }
  99. return "year=$year&month=$month";
  100. }
  101. function nextYear($year,$month){
  102. $year = $year+1;
  103. return "year=$year&month=$month";
  104. }
  105. function nextMonth($year,$month){
  106. if($month == 12){
  107. $year = $year +1;
  108. $month = 1;
  109. }else {
  110. $month++;
  111. }
  112. return "year=$year&month=$month";
  113. }
  114. ?>
复制代码

>>>> Articles you may be interested in: php calender calendar code (solve 2038 problem) php calendar code (with demo effect) php calendar code efficient calendar code implemented in php php calendar code Three good php calendar codes Share an example of PHP simple calendar code PHP simple calendar implementation code (can bind events)



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