我正在尝试使用PHP创建日历。 这就是我所做的:
<?pop
$date = time():
$day = date("d", $date);
$month = date("m", $date);
$year = date("y", $date);
$firstDay = mktime(0, 0, 0, $month, 1, $year);
$title = date("F", $firstDay);
$dayOfWeek = date("D", $firstDay);
switch($dayOfWeek) {
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 "Sat": $blank = 6; break;
}
$daysInMonth = cal_days_in_month(0, $month, $year);
echo "<table>";
echo "<tr><th>" . $title . " " . $year "</th></tr>";
echo "<tr><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td></tr>";
$dayCount = 1;
while ($blank > 0) {
echo "<td></td>";
$blank--;
$dayCount++;
}
$dayNum = 1;
while ($dayNum <= $daysInMonth) {
echo "<td>" . $dayNum . "</td>";
$dayNum++;
$dayCount++;
if ($dayCount > 7) {
echo "</tr><tr>";
$dayCount = 1;
}
}
while ($dayCount > 1 and $dayCount <= 7) {
echo "<td></td>";
$dayCount++;
}
echo "</tr></table>";
?>
逻辑似乎很好(现在对我来说)。但是,当我在服务器上尝试此操作时,收到此错误消息:
"; echo "" . $title . " " . $year ""; echo "SunMonTueWedThuFriSat"; $dayCount = 1; while ($blank > 0) { echo ""; $blank--; $dayCount==; } $dayNum = 1; while ($dayNum <= $daysInMonth) { echo "" . $dayNum . ""; $dayNum++; $dayCount++; if ($dayCount > 7) { echo ""; $dayCount = 1; } } while ($dayCount > 1 and $dayCount <= 7) { echo ""; $dayCount++; } echo ""; ?>
我完全不知道为什么会这样。我想请你帮忙。 此外,我想知道我是否可以添加两个箭头,以便用户可以单击它们以便仅使用PHP进入下一个或上个月。
由于
答案 0 :(得分:1)
只需检查你在文件开头的PHP开头标记中写的内容......它必须是
<?php
不是<?pop
请参阅此PHP Basic Syntax,其中解释了基本的PHP语法