Home  >  Article  >  Backend Development  >  PHP simple calendar implementation code (can bind events)

PHP simple calendar implementation code (can bind events)

WBOY
WBOYOriginal
2016-07-25 08:56:051556browse
  1. /**
  2. * php simple calendar
  3. * edit: bbs.it-home.org
  4. */
  5. if(empty($year))$year=date("Y"); //Initialize year
  6. if(empty($month)) $month=date("n"); //Initialize the month
  7. $wd_ar=array("Day","One","Two","Three","Four","Five","Six"); / /Week array
  8. $wd=date("w",mktime(0,0,0,$month,1,$year)); //What day of the week is the first day of the month
  9. //Year link
  10. $y_lnk1=$ year<=1970?$year=1970:$year-1;
  11. $y_lnk2=$year>=2037?$year=2037:$year+1;
  12. //month link
  13. $m_lnk1=$month<=1? $month=1:$month-1;
  14. $m_lnk2=$month>=12?$month=12:$month+1;
  15. echo <<< EOT
  16. EOT;
  17. for($i=0;$i<7;$i++) {
  18. print "
  19. ";
  20. $tnum=$wd+date("t",mktime(0,0,0,$month,1,$year));
  21. for($ i=0;$i<$tnum;$i++) {
  22. $date=$i+1;
  23. if($i%7==0) print '
  24. ';
  25. print '
  26. ";
  27. if($i%7==6 ) print "
  28. ";
  29. }
  30. if($i%7<6 && $i%7>0) print '
  31. ';
  32. if($i%7==6) print "
  33. ";
  34. print '?>
  35. Copy the code

    It's very simple, right? The above is the php calendar code introduced in this section, which implements some functions of the basic calendar: display of year, month, date, and week.

    >>>> Articles you may be interested in: php calender calendar code (solve 2038 problem) php calendar code (with demo effect) php calendar code sharing simple and practical php calendar code 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

    < $year year> < $month month>
    $wd_ar[$i]
  36. }
  37. print "
  38. ';
  39. if($i>=$wd) print $date-$wd;
  40. print "


Statement:
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