php日历
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php日历相关的知识,希望对你有一定的参考价值。
<?php /** * 日历 */ if (function_exists(‘date_default_timezone_set‘)) { date_default_timezone_set(‘Asia/Hong_Kong‘); } $date = isset($_GET[‘date‘]) ? $_GET[‘date‘] : date(‘Y-m-d‘); $date = getdate(strtotime($date)); $month_cn = array( ‘January‘ => ‘01‘, ‘February‘ => ‘02‘, ‘March‘ => ‘03‘, ‘April‘ => ‘04‘, ‘May‘ => ‘05‘, ‘June‘ => ‘06‘, ‘July‘ => ‘07‘, ‘August‘ => ‘08‘, ‘September‘ => ‘09‘, ‘October‘ => ‘10‘, ‘November‘ => ‘11‘, ‘December‘ => ‘12‘, ); $end = getdate(mktime(0, 0, 0, $date[‘mon‘] + 1, 1, $date[‘year‘]) - 1); $start = getdate(mktime(0, 0, 0, $date[‘mon‘], 1, $date[‘year‘])); $pre = date(‘Y-m-d‘, $start[0] - 1); $next = date(‘Y-m-d‘, $end[0] + 86400); $PHP_SELF = $_SERVER[‘PHP_SELF‘]; $html = ‘<table style="border-collapse:collapse;border-spacing:0;line-height:30px; font-family:Verdana,宋体;font-size:12px;width:300px;border:1px solid #aaa" border=1>‘; $html.= ‘<tr align=center>‘; $html.= ‘<td><a href="‘ . $PHP_SELF . ‘?date=‘ . $pre . ‘" style="text-decoration:none"><</a></td>‘; $html.= ‘<td colspan=5>‘ . $date[‘year‘] . ‘ - ‘ . $month_cn[$date[‘month‘]] . ‘ <a href="‘ . $PHP_SELF . ‘">今天</a> </td>‘; $html.= ‘<td><a href="‘ . $PHP_SELF . ‘?date=‘ . $next . ‘" style="text-decoration:none">></a></td>‘; $html.= ‘</tr>‘; $arr_tpl = array( 0 => ‘‘, 1 => ‘‘, 2 => ‘‘, 3 => ‘‘, 4 => ‘‘, 5 => ‘‘, 6 => ‘‘ ); $date_arr = array(); $j = 0; for ($i = 0; $i < $end[‘mday‘]; $i++) { if (!isset($date_arr[$j])) { $date_arr[$j] = $arr_tpl; } $date_arr[$j][($i + $start[‘wday‘]) % 7] = $i + 1; if ($date_arr[$j][6]) { $j++; } } $html.= " <tr align=center style=‘background:#eee‘> <td>一</td> <td>二</td> <td>三</td> <td>四</td> <td>五</td> <td>六</td> <td>日</td> </tr>"; foreach ($date_arr as $value) { $html.= ‘<tr align=center>‘; foreach ($value as $v) { if ($v) { if ($month_cn[$date[‘month‘]] == date(‘m‘) && $v == date(‘d‘)) { $html.= ‘<td style="background:#FFC993"><span style="color:#f00;font-weight:bold">‘ . $v . ‘</span></td>‘; } else { $html.= ‘<td>‘ . $v . ‘</td>‘; } } else { $html.= ‘<td> </td>‘; } } $html.= ‘</tr>‘; } $html.= ‘</table>‘; echo $html; ?>
;
以上是关于php日历的主要内容,如果未能解决你的问题,请参考以下文章