Parse error: syntax error, unexpected $end in ...php

本文介绍了解决PHP中出现的Parse Error: syntax error, unexpected '$end' 的方法。问题可能源于缺少大括号、类定义错误或使用了短标签。文章详细解释了如何通过配置php.ini文件中的short_open_tag参数来启用短标签。

同事留下的一份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。

 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值