Home  >  Article  >  Backend Development  >  Share an example of PHP simple calendar code

Share an example of PHP simple calendar code

WBOY
WBOYOriginal
2016-07-25 08:56:07849browse
";
  • echo $begin_mark.$content.$end_mark ;
  • }
  • ?>
  • Community Calendar
  • //Get the current date
  • $firstday = getdate(mktime(0,0,0, date("m"),1,date("Y")));
  • setup();
  • //Display the name of the table
  • echo "
    ";
  • echo "
    1. //calendar.php
    2. /*******************************
    3. * Function to determine whether it is a leap year*
    4. * Can be improved based on more complex algorithms*
    5. ** *****************************/
    6. function leap_year($year)
    7. {
    8. if($year% 4 == 0) // basic rule
    9. {
    10. return true; // is leap year
    11. }
    12. else
    13. {
    14. return false;
    15. }
    16. }
    17. /*******************************
    18. * Assign values ​​to some variables*
    19. * Pay special attention to the assignment in February*
    20. * ********************************/
    21. function setup()
    22. {
    23. global $mon_num;
    24. $mon_num=array(31,30,31,30,31,30,31,31,30,31,30,31);
    25. global $mon_name;
    26. $mon_name=array("一","二","三","四",
    27. "五","六","七","八",
    28. "九","十","十一","十二");
    29. if (leap_year($firstday[year])) // basic rule
    30. {
    31. $mon_num[1]=29; // is leap year
    32. }
    33. else
    34. {
    35. $mon_num[1]=28;
    36. }
    37. }
    38. /*******************************
    39. * Display a cell in the table*
    40. * The displayed content and color are variable*
    41. * ********************************/
    42. function showline($content,$show_color)
    43. {
    44. $begin_mark = "
    ";
  • $begin_mark =$begin_mark."";
  • $end_mark = "
  • ";
  • echo "
  • ";
  • //Header
  • $weekDay[0] = " day";
  • $weekDay[1] = "one";
  • $weekDay[2] = "two";
  • $weekDay[3] = "three";
  • $weekDay[4] = "four";
  • $weekDay [5] = "five";
  • $weekDay[6] = "six";
  • echo "
  • ";
  • //Display table The first line of
  • for ($dayNum = 0; $dayNum < 7; ++$dayNum) {
  • showline($weekDay[$dayNum],"red");
  • }
  • echo"
  • ";
  • $toweek=$firstday[wday];//What day of the week is the first day of this month
  • $lastday=$mon_num[$firstday[mon]-1];//What day of the week is the last day of this month
  • $day_count = 1;//The current number of days that should be displayed
  • $up_to_firstday = 1;//Whether it is displayed to the first day of this month
  • for ($row = 0; $row <= ($lastday+$toweek-1 )/7; ++$row)//How many weeks are there in this month
  • { echo "
  • ";
  • for ($col=1; $col<=7; ++$ col)
  • {
  • //Everything displayed before the first day is "empty"
  • if (($up_to_firstday <= $toweek) ||($day_count>$lastday))
  • {
  • echo "
  • ";
  • $up_to_firstday++;
  • }
  • else
  • {
  • //Show a day in this month
  • showline($day_count,"blue");
  • $day_count++;
  • }
  • }
  • echo "< ;/TR>";
  • }
  • echo "
  • ";
  • echo "";
  • echo "$firstday[year]年 ".$mon_name [$firstday[mon]-1]."Month Calendar";
  • echo "";
  • echo "
  •  
    ";
  • echo "";
  • ?>
  • >>>> 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 PHP simple calendar implementation code (can bind events)



  • 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
    Previous article:php function to randomly display imagesNext article:php function to randomly display images

    Related articles

    See more