同事留下的一份php代码,在他的机器上运行都很正常,跑到我机器上,就总数显示
Parse error: syntax error, unexpected $end in (apache路径)\global.php on line 11。反复找了好几次,也没有看到少括号。从网上搜到了如下文字:
--------------------------------------------------------------------
In
PHP 5, the following error may appears as an error entry in Apache error log or simply displays on PHP web page, even if calling to php scripts with php_info() works perfectly and successfully returns information on PHP configurations:
Parse Error: syntax error, unexpected $end in ….. scripts.php on line …
The error may caused by a missing curly bracket in PHP script coding. Beside, it may also caused by error in PHP
coding in class definition, as in PHP, a class definition cannot be broke up and distributed into multiple files, or into multiple PHP blocks, unless the break is within a method declaration.
But more commonly, the error is often caused by the use of Short Open tags in PHP,
To use short open tags, it must be enabled in PHP.INI. Search for short_open_tag in PHP.INI, and change the value
to On. The line should look line:
short_open_tag = On
--------------------------------------------------------------------------------------
将php.ini文件中的short_open_tag = off 项,设置成on,重启服务器即可。
short_open_tag 是什么呢?
决定是否允许使用代码开始标志的缩写形式(<? ?> )。
如果要和 XML 结合使用 PHP,可以禁用此选项,以便于嵌入使用<?xml ?> ;例如可以通过php来输出,例如:<?php echo '<?xml version="1.0"'; ?> 。
如果short_open_tag = Off,,必须使用 PHP 代码开始标志的完整形式(<?php ?> )。
注意:本指令也会影响到缩写形式 <?= ,它和 <? echo 等价。使用此缩写需要short_open_tag 的值为 On。
本文介绍了解决PHP中出现的Parse Error: syntax error, unexpected '$end' 的方法。问题可能源于缺少大括号、类定义错误或使用了短标签。文章详细解释了如何通过配置php.ini文件中的short_open_tag参数来启用短标签。

723

被折叠的 条评论
为什么被折叠?



