注釋

PHP 支持 C,C++ 和 Unix Shell 風(fēng)格(Perl 風(fēng)格)的注釋。例如:

<?php
    
echo 'This is a test'// 這是單行 c++ 樣式注釋
    /* 這是一條多行注釋
       另一行也是注釋 */
    
echo 'This is yet another test';
    echo 
'One Final Test'# 這是單行 shell 風(fēng)格的注釋
?>

單行注釋僅僅注釋到行末或者當(dāng)前的 PHP 代碼塊,視乎哪個(gè)首先出現(xiàn)。這意味著在 // ... ?> 或者 # ... ?> 之后的 HTML 代碼將被顯示出來(lái):?> 跳出了 PHP 模式并返回了 HTML 模式,//# 并不能影響到這一點(diǎn)。

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

C 風(fēng)格的注釋在碰到第一個(gè) */ 時(shí)結(jié)束。要確保不要嵌套 C 風(fēng)格的注釋。試圖注釋掉一大塊代碼時(shí)很容易出現(xiàn)該錯(cuò)誤。

<?php
 
/*
    echo 'This is a test'; /* 這個(gè)注釋會(huì)引發(fā)問題 */
 
*/
?>