PHP Calendar code three good PHP calendar code

Source: Internet
Author: User
  1. /**
  2. * PHP Calendar
  3. * by bbs.it-home.org
  4. */
  5. if (function_exists (' Date_default_timezone_set ')) {
  6. Date_default_timezone_set (' asia/chongqing ');
  7. }
  8. $date = isset ($_get[' date ')? $_get[' Date ': Date (' y-m-d ');
  9. $date = getdate (Strtotime ($date));
  10. $end = getdate (mktime (0, 0, 0, $date [' mon '] + 1, 1, $date [' Year '])-1);
  11. $start = getdate (mktime (0, 0, 0, $date [' mon '], 1, $date [' Year ']);
  12. $pre = Date (' y-m-d ', $start [0]-1);
  13. $next = Date (' y-m-d ', $end [0] + 86400);
  14. $html = '
  15. $html. = '
  16. $html. = '
  17. $html. = '
  18. $html. = '
  19. $html. = '
  20. $arr _tpl = Array (0 = ', 1 = ', 2 = ', 3 = ', 4 = ', 5 = ', 6 = ');
  21. foreach ($value as $v) {
  22. } else {
  23. }
  24. }
  25. }
  26. $date _arr = Array ();
  27. $j = 0;
  28. for ($i = 0; $i < $end [' Mday ']; $i + +) {
  29. if (!isset ($date _arr[$j])) {
  30. $date _arr[$j] = $arr _tpl;
  31. }
  32. $date _arr[$j] [($i + $start [' wday '])%7] = $i +1;
  33. if ($date _arr[$j][6]) {
  34. $j + +;
  35. }
  36. }
  37. foreach ($date _arr as $value) {
  38. $html. = '
  39. if ($v) {
  40. if ($v = = $date [' mday ']) {
  41. $html. = '
  42. $html. = '
  43. } else {
  44. $html. = '
  45. }
  46. $html. = '
  47. $html. = '
  48. '; '; '; '; '; '; '; '; '; '; ';
    -' . $date [' Year ']. ';' . $date [' Month ']. '+
    ' . $v. '' . $v. '
    ';
  49. Echo $html;
  50. ?>
Copy Code

2,php Calendar Code 2

  1. /**
  2. * Calendar
  3. */
  4. if (function_exists (' Date_default_timezone_set ')) {
  5. Date_default_timezone_set (' asia/chongqing ');
  6. }
  7. $date = isset ($_get[' date ')? $_get[' Date ': Date (' y-m-d ');
  8. $date = getdate (Strtotime ($date));
  9. $end = getdate (mktime (0, 0, 0, $date [' mon '] + 1, 1, $date [' Year '])-1);
  10. $start = getdate (mktime (0, 0, 0, $date [' mon '], 1, $date [' Year ']);
  11. $pre = Date (' y-m-d ', $start [0]-1);
  12. $next = Date (' y-m-d ', $end [0] + 86400);
  13. $html = '
  14. $html. = '
  15. $html. = '
  16. $html. = '
  17. $html. = '
  18. $html. = '
  19. $arr _tpl = Array (0 = ', 1 = ', 2 = ', 3 = ', 4 = ', 5 = ', 6 = ');
  20. foreach ($value as $v) {
  21. } else {
  22. }
  23. }
  24. }
  25. $date _arr = Array ();
  26. $j = 0;
  27. for ($i = 0; $i < $end [' Mday ']; $i + +) {
  28. if (!isset ($date _arr[$j])) {
  29. $date _arr[$j] = $arr _tpl;
  30. }
  31. $date _arr[$j] [($i + $start [' wday '])%7] = $i +1;
  32. if ($date _arr[$j][6]) {
  33. $j + +;
  34. }
  35. }
  36. foreach ($date _arr as $value) {
  37. $html. = '
  38. if ($v) {
  39. if ($v = = $date [' mday ']) {
  40. $html. = '
  41. $html. = '
  42. } else {
  43. $html. = '
  44. }
  45. $html. = '
  46. $html. = '
  47. align= "center" style= "line-height:150%; Font-family:verdana, song body; font-size:12px; " > '; '; '; '; '; '; '; '; '; '; ';
    -' . $date [' Year ']. ';' . $date [' Month ']. '+
    ' . $v. '' . $v. '
    ';
  48. Echo $html;
  49. ?>
Copy Code

3,php Calendar Code Three:

  1. /**

  2. * PHP Calendar Code
  3. * edit:bbs.it-home.org
  4. */
  5. function Calendar ()
  6. {
  7. if ($_get[' ym ')
  8. {
  9. $year = substr ($_get[' ym '],0,4);
  10. $month = substr ($_get[' ym '],4, (strlen ($_get[' ym ")-4));

  11. if ($month >12)

  12. {
  13. $year + = Floor ($month/12);
  14. $month = $month% 12;
  15. }
  16. if ($year > 2030) $year = 2030;
  17. if ($year < 1980) $year = 1980;
  18. }

  19. $year = Isset ($year)? $year: Date (' Y ');

  20. $month = Isset ($month)? $month: Date (' n ');

  21. if ($year ==date (' Y ') && $month ==date (' n ') $today = date (' j ');

  22. if ($month-1 = = 0)

  23. $prevmonth = ($year-1). " 12 ";
  24. else $prevmonth = $year. ($month-1);

  25. if ($month +1 = = 13)

  26. $nextmonth = ($year + 1). " 1 ";
  27. else $nextmonth = $year. ($month + 1);

  28. $prevyear = ($year-1). $month;

  29. $nextyear = ($year + 1). $month;

  30. Echo <<

  31. VKN;
  32. $count + +;
  33. if ($count%7==0) echo "
  34. $count + +;
  35. }

  36. }
  37. All of the Month
  38. for ($i = 1; $i <= $daysofmonth; $i + +)
  39. {
  40. $css = ($count%7==0 | | $count%7==1)? " Weekday ":" Normalday ";
  41. if ($i = = $today) $css. = "Today";

  42. echo "

  43. }
  44. A few days before next month
  45. for ($i = 1; $i <= 6-$weekofendday; $i + +)
  46. {
  47. echo "
  48. Echo <<

  49. $nowtime = Mktime (0,0,0, $month, 1, $year);//1th to seconds of the month
  50. $daysofmonth = Date (t, $nowtime);//Days of the Month
  51. $weekofbeginday = Date (w, $nowtime);//The first day of the month is the days of the week
  52. $weekofendday = Date (W,mktime (0,0,0, $month +1,0, $year));//The Last day of the month is the days of the week
  53. $daysofprevmonth = Date (T,mktime (0,0,0, $month, 0, $year));//number of days last month

  54. $count = 1;//Count

  55. List the days after last month
  56. for ($i = 1; $i <= $weekofbeginday; $i + +)
  57. {
  58. echo "
  59. "; "; "; ";
    << < $year-$month > >>
    Day One Two Three Four Five Six
    ". ($daysofprevmonth-$weekofbeginday + $i). "". $i."
    ". $i."
  60. VKN;
  61. }
  62. ?>
  63. Calendar
Copy Code

>>> you may be interested in the article: PHP Calender Calendar code (solve 2038 problems) PHP Calendar code (with demo effect) PHP Calendar code sharing simple and useful PHP calendar code PHP calendar code PHP implementation of the efficient calendar code to share a sample PHP simple calendar code PHP simple Calendar Implementation code (bindable events)

  • 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.