Php calendar code: three good php calendar codes-php Tutorial

Source: Internet
Author: User
Php calendar code: three good php calendar codes

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

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,; font-size: 12px;"> '; '; '; '; '; '; '; '; '; '; ';
    -'. $ Date ['Year'].'; '. $ date ['month'].'+
    '. $ V .''. $ V .'
    ';
  48. Echo $ html;
  49. ?>

3. php calendar code 3:

  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 );
  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. $ Nowtime = mktime (0, 0, 0, $ month, 1, $ year); // convert the value 1 to the second of the current month
  37. $ Daysofmonth = date (t, $ nowtime); // Number of days in the current month
  38. $ Weekofbeginday = date (w, $ nowtime); // The Day of the week on the first day of the month
  39. $ Weekofendday = date (w, mktime (, 0, 0, $ month +, $ year); // The last day of the month is the day of the week.
  40. $ Daysofprevmonth = date (t, mktime (, 0, $ month, 0, $ year); // Number of days in the previous month

  41. $ Count = 1; // count

  42. // List the days after the previous month
  43. For ($ I = 1; $ I <= $ weekofbeginday; $ I ++)
  44. {
  45. Echo"
  46. }
  47. // All for the current month
  48. For ($ I = 1; $ I <= $ daysofmonth; $ I ++)
  49. {
  50. $ Css = ($ count % 7 = 0 | $ count % 7 = 1 )? "Weekday": "normalday ";
  51. If ($ I = $ today) $ css. = "today ";

  52. Echo"

  53. }
  54. // A few days before next month
  55. For ($ I = 1; $ I <= 6-$ weekofendday; $ I ++)
  56. {
  57. Echo"
  58. Echo <

  59. "; "; "; ";
    < < $ Year-$ month > >
    Day I II 3. Thu V. Sat.
    ". ($ Daysofprevmonth-$ weekofbeginday + $ I )."". $ I ."
    ". $ I ."
  60. VKN;
  61. }
  62. ?>
  63. Calendar

>>> 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 sharing example PHP simple 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.