Share a simple PHP calendar code example

Source: Internet
Author: User
Share a simple PHP calendar code example
  • Echo $ begin_mark. $ content. $ end_mark;
  • }
  • ?>
  • Community Calendar
  • // Obtain the current date
  • $ Firstday = getdate (mktime (0, 0, 0, date ("m"), 1, date ("Y ")));
  • Setup ();
  • // Display the table name
  • Echo" ";
  • Echo"
  • ";

    1. // Calendar. php
    2. /*******************************
    3. * Functions used to determine whether a leap year is used *
    4. * Improvements can be made 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 value assignment for February *
    20. *******************************/
    21. Function setup ()
    22. {
    23. Global $ mon_num;
    24. $ Mon_num = array (, 30, 31 );
    25. Global $ mon_name;
    26. $ Mon_name = array ("1", "2", "3", "4 ",
    27. "5", "6", "7", "8 ",
    28. "9", "10", "11", "12 ");
    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 grid 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"
  • $ Toweek = $ firstday [wday]; // The first day of the month is the day of the week.
  • For ($ col = 1; $ col <= 7; ++ $ col)
  • $ Up_to_firstday ++;
  • }
  • // Header
  • $ WeekDay [0] = "day ";
  • $ WeekDay [1] = "1 ";
  • $ WeekDay [2] = "2 ";
  • $ WeekDay [3] = "3 ";
  • $ WeekDay [4] = "4 ";
  • $ WeekDay [5] = "5 ";
  • $ WeekDay [6] = "6 ";
  • Echo"
  • // Display the first row of the table
  • For ($ dayNum = 0; $ dayNum <7; ++ $ dayNum ){
  • Showline ($ weekDay [$ dayNum], "red ");
  • }
  • Echo"
  • $ Lastday = $ mon_num [$ firstday [mon]-1]; // The last day of the month is the day of the week.
  • $ Day_count = 1; // Number of days to be displayed
  • $ Up_to_firstday = 1; // whether it is displayed on the first day of the month
  • For ($ row = 0; $ row <= ($ lastday + $ toweek-1)/7; + + $ row) // this month has several weeks
  • {Echo"
  • {
  • // "Null" is displayed before the first day"
  • If ($ up_to_firstday <= $ toweek) | ($ day_count> $ lastday ))
  • {
  • Echo"
  • }
  • Else
  • {
  • // Display a day of the month
  • Showline ($ day_count, "blue ");
  • $ Day_count ++;
  • }
  • }
  • Echo"
  • Echo"
  • "; "; "; "; "; "; ";
    ";
  • Echo "";
  • Echo "$ firstday [year] year". $ mon_name [$ firstday [mon]-1]. "Monthly & nbsp calendar ";
  • Echo "";
  • Echo"
  •  
    ";
  • Echo"";
  • ?>
  • >>> Articles you may be interested in: php calender calendar code (solving 2038 issues) php calendar code (with demo effect) php calendar code sharing simple and practical php calendar code php efficient calendar code php calendar code three good php calendar code php simple calendar implementation code (events can be bound)

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.