我刚刚开始我的PHP旅程并正在完成创建简单日历的教程。我在Codepad中遇到语法错误,但无法找到修复程序。我确定这是一件我没见过的简单事。对于笔记感到抱歉,我一直试图尽可能地注释,所以我不会迷路。
错误是:
Parse error: syntax error, unexpected ',' on line 10. (the $day=('d', $date) declaration)
代码:
<?php
// current date variable
$date = time ();
//day, month and year variables
$day = ('d', $date);
$month = ('m', $date);
$year = ('Y', $date);
// first day of the month
$monthfirstday = mktime(0,0,0,$month, 1, $year);
// get the name of the month
$monthtitle = ('F', $monthfirstday);
// first day of the week
$weekday = ('D', $monthfirstday);
// identify the days of the week
switch ($weekday) {
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;
}
// number of days in the month
$daysinmonth = cal_days_in_month(0, $month, $year);
// include the html
echo "<div id='calendar-wrap'>";
echo "<table border=6 width=394><tr><th colspan=60> $monthtitle $year</th></tr>";
echo "
<tr>
\n\t\t<td width=62>SUN</td>
\n\t\t<td width=62>MON</td>
\n\t\t<td width=62>TUES</td>
\n\t\t<td width=62>WEDS</td>
\n\t\t<td width=62>THURS</td>
\n\t\t<td width=62>FRI</td>
\n\t\t<td width=62>SAT</td>
</tr>
";
$daycount = 1;
echo "<tr>";
// dealing with the days of the month
$blank > 0
{
echo "<td></td>";
$blank = $blank-1;
$daycount++;
}
// set the day number to 1
$daynumber = 1;
// count the days of the month
while
( $daynumber <= $daysinmonth )
{
echo "<td> $daynumber </td>";
// increase the day count until the month ends
$daynumber++;
$daycount++;
// add a new row every 7 days
if ($daycount > 7)
{
echo "</tr><tr>";
$daycount = 1;
}
}
// fill in blank days if necessary
while
($daycount > 1 && $daycount <= 7)
{
echo "<td> </td>";
$daycount++;
}
echo "</tr></table></div>";
?>
提前致谢,
麦克
答案 0 :(得分:6)
您的功能缺失了!
$day = date('d', $date);
答案 1 :(得分:3)
你去......
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
答案 2 :(得分:1)
我认为你正在尝试这样做:
$day = date('d', $date);
答案 3 :(得分:0)
这是错误。错过了功能:)
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);