为什么这段代码会产生“语法错误,意外的‘=’”?
$text . = '1 paragraph';
$text . = '2 paragraph';
$text . = '3 paragraph';
echo $text;
此代码给出错误语法错误,意外的“=”
。
问题是什么?
$text . = '1 paragraph';
$text . = '2 paragraph';
$text . = '3 paragraph';
echo $text;
This code gives error syntax error, unexpected '='
.
What is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果无论如何你都要输出所有这些,那为什么还要连接呢?只是回应它:
If you are going to output all of that anyway, then why concatenate at all? Just echo it:
点和等号之间的空间?
.=
而不是。 =
The space between the dot and the equal?
.=
instead of. =
其他人已经指出了错误:
.
和=
之间有空格。这是语法/解析错误。当 PHP 看到
.
后跟空格时,它会将.
作为单独的标记,用于字符串连接。现在它后面需要一个字符串或一个变量。但是当它看到=
时,它会抛出解析错误,因为它与 PHP 语法不匹配。Others have already pointed out the error: space between
.
and=
.This is a syntax/parse error. When PHP sees the
.
followed by space it takes.
as a separate token which is used for string concatenation. Now it expects a string or a variable after it. But when it sees the=
it throws the parse error as it does not match the PHP grammar.也可以像这样 echo
echo '1 paragraph'.'2 paragraph'.'3 paragraph';
Also can echo like this
echo '1 paragraph'.'2 paragraph'.'3 paragraph';
我想你想要:
请注意,第一行不使用
.=
,而只使用=
I think you want:
Note that the first line does not use
.=
, and just uses=