PHP 支持 C,C++ 和 Unix Shell 风格(Perl 风格)的注释。例如:

<?php     echo "This is a test"; // This is a one-line c++ style comment     /* This is a multi line comment        yet another line of comment */     echo "This is yet another test";     echo "One Final Test"; # This is shell-style style comment ?>

单行注释仅仅注释到行末或者当前的 PHP 代码块,视乎哪个首先出现。这意味着在 // ?> 之后的 HTML 代码将被显示出来:?> 跳出了 PHP 模式并返回了 HTML 模式,// 并不能影响到这一点。如果启用了 asp_tags 配置选项,其行为和 // %> 相同。不过, 标记在单行注释中不会跳出 PHP 模式。

<h1>This is an <?php # echo "simple";?> example.</h1> <p>The header above will say 'This is an example'.

C 风格的注释在碰到第一个 */ 时结束。小心不要嵌套 C 风格的注释,当注释大量代码时,可能犯该错误。

<?php /*     echo "This is a test"; /* This comment will cause a problem */ */ ?>
最后修改:2015 年 11 月 06 日
如果觉得我的文章对你有用,请随意赞赏