在PHP中,为什么没有显示解析错误?
I was running the following PHP code:
我运行的PHP代码如下:
<?php
</script>
?>
There were no parse errors and the output was "?>
" (example).
没有解析错误,输出是“?”>”(例子)。
In similar cases I do get a parse error:
在类似的情况下,我确实得到了一个解析错误:
<?php
</div>
?>
Parse error: syntax error, unexpected '<' in ...
解析错误:语法错误,在…
Why doesn't <?php </script> ?>
give the same error?
为什么不< ?php ?> ?
2 个解决方案
#1
271
This must be because there are various ways of starting a block of PHP code:
这一定是因为有很多方法可以启动一个PHP代码块:
<? ... ?>
(known asshort_open_tag
)< ?…? >(称为short_open_tag)
<?php ... ?>
(the standard really)< ?php……? >(标准真的)
<script language="php"> ... </script>
(not recommended)< =“php脚本语言>…< /脚本>(不推荐)
<% ... %>
(deprecated and removed ASP-style tag after 5.3.0)< %……%>(在5.3.0之后弃用和移除asp样式的标签)
Apparently, you can open a PHP block one way, and close it the other. Didn't know that.
显然,您可以以一种方式打开一个PHP块,然后以另一种方式关闭它。不知道。
So in your code, you opened the block using <?
but PHP recognizes </script>
as the closer. What happened was:
在你的代码中,你使用 更接近。发生了什么是:
<?php <----- START PHP
</script> <----- END PHP
?> <----- JUST GARBAGE IN THE HTML
更多相关文章
- php异常和错误处理
- 正则表达式匹配wordpress类似的短代码,用于自闭和封闭。
- php文件显示代码在Chrome
- 怎么知道php代码运行时调用了那个类、那个方法呢?
- APMServ 在 Win7 下出现“APMServ-Apache 服务因 函数不正确。
- 从。net调用Magento API,并得到“位于XYZ的HTTP服务太忙”的错误
- 我得到了“致命错误:未捕获的SoapFault异常:[客户机]SoapClient:
- PHP / Ajax:如何在成功登录后启动会话(剩余代码工作)
- ajax php bomt头 utf-8带来的奇怪问题。。返回值false 判断也是f