添加?>到PHP评论

时间:2017-05-12 14:21:51

标签: php escaping comments

我对PHP很新,并试图为我的共同学习者创建一个社区学习代码来帮助他们,我想在评论中加入编码提示。我尝试写以下内容:

# 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 ?>

但是,在评论中键入?>会结束文件和评论。我怎么逃避这个?我尝试使用\,但这似乎不起作用,也会混淆评论意义。

这是怎么做到的?

1 个答案:

答案 0 :(得分:2)

使用结束标记和起始标记,PHP对单行注释不起作用。虽然您可以使用多条评论:

/* 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

中提到了这一点
  

" one-line"注释样式只注释到行的末尾或当前的PHP代码块,以先到者为准。这意味着// ...>之后的HTML代码或#...?>将被打印:?>突破PHP模式并返回HTML模式,//或#不能影响它。