【问题标题】:Adding ?> to a PHP comment添加 ?> 到 PHP 注释
【发布时间】:2017-05-12 14:21:51
【问题描述】:

我对 PHP 还很陌生,正在尝试为我的共同学习者创建一段社区学习代码来帮助他们,我想在 cmets 中提供一个编码技巧。我尝试编写以下内容:

# Tip -- when PHP is the only code in a file, don't put ?> at the end as this can cause bugs if white-space or additional PHP code is written to the end of the file after the file is initially created, after the ?>

但是,在注释中键入 ?> 会结束文件和注释。我该如何逃脱呢?我尝试使用\,但这似乎不起作用,并且还会混淆评论的意义。

这是怎么做到的?

【问题讨论】:

  • 尝试使用多行注释,例如 /* */
  • 我试一试...

标签: php escaping comments


【解决方案1】:

PHP 不适用于使用结束标签和开始标签的单行 cmets。虽然您可以使用多行注释:

/* Tip -- when PHP is the only code in a file, don't put ?> at the end as this can cause bugs if white-space or additional PHP code is written to the end of the file after the file is initially created, after the ?> */

请注意,Comment Documentation for PHP 中提到了这一点:

“单行”注释样式仅注释到行尾或当前 PHP 代码块,以先到者为准。这意味着 // ... ?> 或 # ... ?> 之后的 HTML 代码将被打印: ?> 退出 PHP 模式并返回 HTML 模式,而 // 或 # 不会影响它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-29
    • 2011-09-01
    • 2013-07-25
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    相关资源
    最近更新 更多