我已经从about.com上面的代码。除了2015年8月之外,一切运作良好。开始日期应该是星期六,但日历会显示星期一。我迄今检查的其他月份是正确的。PHP日历与错误的开始日期为2015年8月
任何提示?
<?php
function calendar() {
date_default_timezone_set('UTC');
$date = time(); // it was removed orginally.
if (ISSET($_REQUEST['emonth'])&& ISSET($_REQUEST['eyear'])){
$month = $_REQUEST['emonth'];
$year = $_REQUEST['eyear'];
} else {
$month = date('m', $date);
$year = date('Y', $date);
}
$first_day = mktime(0,0,0,$month, 1, $year);
echo date('D', $first_day);
$title = date('F', $first_day);
$day_of_week = date('D', $first_day);
switch($day_of_week){
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sar": $blank = 6; break;
}
$days_in_month = cal_days_in_month(0, $month, $year);
echo '<table class="event">
<tr>
<td colspan="7">'.$title.'-'.$year.'</td>
</tr><tr>
<th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th>
</tr>';
$day_count = 1;
echo '<tr>';
while ($blank > 0) {
echo '<td></td>';
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
while ($day_num <= $days_in_month){
echo "<td>$day_num</td>";
$day_num++;
$day_count++;
if ($day_count > 7) {
echo '</tr><tr>';
$day_count = 1;
while ($day_count > 1 && $day_count <= 7) {
echo '<td></td>';
$day_count++;
}
}
}
echo '</tr>
</table>';
}
calendar();
?>
解决
有肌氨酸代替周六的在开关壳体拼写错误。由于它在我检查过的大多数月份都有效,所以我忽略了它。它现在在纠正之后起作用。
谢谢你们
'$ month = date('m',$ date); $ year = date('Y',$ date);'....'$ date'定义在哪里? –
因为'case'Sar'上有一个错字:$ blank = 6;打破;',它应该是'案件“星期六”:$ blank = 6;打破;'。 –
@MarkBaker没有,这就是为什么它抛出一个PHP通知错误。他应该定义它或只是删除它,以获得“今天”的月份和年份。 –