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 as short_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

更多相关文章

  1. php异常和错误处理
  2. 正则表达式匹配wordpress类似的短代码,用于自闭和封闭。
  3. php文件显示代码在Chrome
  4. 怎么知道php代码运行时调用了那个类、那个方法呢?
  5. APMServ 在 Win7 下出现“APMServ-Apache 服务因 函数不正确。
  6. 从。net调用Magento API,并得到“位于XYZ的HTTP服务太忙”的错误
  7. 我得到了“致命错误:未捕获的SoapFault异常:[客户机]SoapClient:
  8. PHP / Ajax:如何在成功登录后启动会话(剩余代码工作)
  9. ajax php bomt头 utf-8带来的奇怪问题。。返回值false 判断也是f

随机推荐

  1. Android广播的一些事
  2. android studio AndroidManifest.xml命名
  3. 关于Android 如何配置测试类
  4. 编译代码报出Android library projects c
  5. android WARNING: Application does not
  6. Android 关于WebView的相关属性
  7. 解决Eclipse3.6中Android 代码自动补全卡
  8. [Android] Android 使用 Greendao 操作 d
  9. Android(安卓)Sqlite 相关汇总
  10. Android实现自定义的 时间日期 控件