PHP syntax error, unexpected $end 错误的一种原因及解决_php技巧

WBOY
Release: 2016-05-17 09:34:36
Original
1203 people have browsed it

Parse error: syntax error, unexpected $end in script.php on line xx
调试了一会后发现产生错误的行是文件中间某行

//$str .= "?>\n";

想起来了 PHP 解释器允许的结尾标记那行还可以用单行注释,即 //$str .= "?>\n"; 被解释成结尾标记前有注释,注释的内容是 //$str .= ",而 ?> 后面的 \n"; 会被解释作 PHP 块外的内容按 HTML 输出出去!结果是给 $str .= "?>\n"; 这行添加 // 成注释后,反而多了个 ?> 的结束标记,造成原来真正的结束标记成了意料之外的(unexpected)了。
解决办法就是直接删掉这一行即可。

PHP 开始和结束标记所在行别写其它东西,是个好习惯。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!