Home >Backend Development >PHP Tutorial >php calendar code three good php calendar codes

php calendar code three good php calendar codes

WBOY
WBOYOriginal
2016-07-25 08:56:042589browse
  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. ';
  17. $html .= '
  18. ';
  19. $html .= '
  20. ';
  21. $html .= '
  22. ';
  23. $html .= '
  24. ';
  25. $arr_tpl = array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '');
  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. ';
  40. foreach ($value as $v) {
  41. if ($v) {
  42. if ($v == $date['mday']) {
  43. $html .= '
  44. ';
  45. } else {
  46. $html .= '
  47. ';
  48. }
  49. } else {
  50. $html .= '
  51. ';
  52. }
  53. }
  54. $html .= '
  55. ';
  56. }
  57. $html .= '
  58. - ' . $date['year'] . ';' . $date['month'] . ' +
    ' . $v . ' ' . $v . '
    ';
  59. echo $html;
  60. ?>
复制代码

2,php日历代码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 = 'align="center" style="line-height:150%; font-family:Verdana,宋体; font-size: 12px;">';
  14. $html .= '
  15. ';
  16. $html .= '
  17. ';
  18. $html .= '
  19. ';
  20. $html .= '
  21. ';
  22. $html .= '
  23. ';
  24. $arr_tpl = array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '');
  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. ';
  39. foreach ($value as $v) {
  40. if ($v) {
  41. if ($v == $date['mday']) {
  42. $html .= '
  43. ';
  44. } else {
  45. $html .= '
  46. ';
  47. }
  48. } else {
  49. $html .= '
  50. ';
  51. }
  52. }
  53. $html .= '
  54. ';
  55. }
  56. $html .= '
  57. - ' . $date['year'] . ';' . $date['month'] . ' +
    ' . $v . ' ' . $v . '
    ';
  58. echo $html;
  59. ?>
复制代码

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. $nowtime = mktime(0,0,0,$month,1,$year);//当月1号转为秒
  33. $daysofmonth = date(t,$nowtime);//当月天数
  34. $weekofbeginday = date(w,$nowtime);//当月第一天是星期几
  35. $weekofendday = date(w,mktime(0,0,0,$month+1,0,$year));//当月最后一天是星期几
  36. $daysofprevmonth = date(t,mktime(0,0,0,$month,0,$year));//上个月天数

  37. $count = 1;//计数

  38. //列出上月后几天
  39. for($i = 1 ; $i <= $weekofbeginday ; $i++)
  40. {
  41. echo "
  42. ";
  43. $count++;
  44. }
  45. //当月全部
  46. for($i = 1 ; $i <= $daysofmonth ; $i++)
  47. {
  48. $css = ($count%7==0 || $count%7==1)?"weekday":"normalday";
  49. if($i == $today) $css .= "today";

  50. echo "

  51. ";
  52. if($count%7==0) echo "
  53. ";
  54. $count++;
  55. }
  56. //下月前几天
  57. for ($i = 1;$i <= 6-$weekofendday;$i++)
  58. {
  59. echo "
  60. ";
  61. }

  62. echo <<

  63. << < $year - $month > >>
    ".($daysofprevmonth-$weekofbeginday+$i)." ".$i."
    ".$i."
  64. VKN;
  65. }
  66. ?>
  67. calendar
复制代码

>>> 您可能感兴趣的文章: php calender日历代码(解决2038问题) php日历代码(附演示效果) php日历代码分享 简单实用的php日历代码 php日历代码 php实现的高效日历代码 分享一例PHP简单日历代码 php简单日历的实现代码(可绑定事件)



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