This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
if
语句末尾有;
。错误原因:
不会导致任何语法错误,因为
if
的正文为空,并且以下块< em>总是被执行。但会导致
Unexpected else
语法错误,因为if
和之前一样有空的主体,后面跟着另一个块blk A
,它不是 if 的主体。现在,当在块后面找到else
if 时,它无法与任何导致此错误的if
匹配。如果我们用语句代替块,也会发生同样的情况:There are
;
at the end ofif
statements.Cause of error:
Will not cause any syntax error as the body of
if
is empty and the following block always gets executed. Butwill cause
Unexpected else
syntax error because theif
as before has empty body and is followed by another blockblk A
which is not if's body. Now when anelse
if found after the block it cannot be matched with anyif
causing this error. The same would happen if we'dstatement
(s) in place of a block:尝试:
两件事:
if 子句末尾有一个分号。这意味着后续的左大括号是始终执行的本地块。这导致了一个问题,因为后来您有一个
else
语句没有附加到if
语句;执行
"$agent"
是不必要的,也不建议这样做。只需传入$agent
。Try:
Two things:
You had a semi-colon at the end of your if clauses. That means the subsequent opening brace was a local block that is always executed. That caused a problem because later you had an
else
statement that wasn't attached to anif
statement; andDoing
"$agent"
is unnecessary and not recommended. Simply pass in$agent
.删除包含“if”的行末尾的分号。
remove the semi-colons from the end of the lines with "if" in them.
为什么这里有分号?
if (preg_match("/MSIE/i", "$agent"));
此处else if (preg_match("/Mozilla/i", "$agent"));< /代码>
Why do you have a semicolon here?
if (preg_match("/MSIE/i", "$agent"));
and hereelse if (preg_match("/Mozilla/i", "$agent"));