Forum und email

註解

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 a one-line shell-style comment
?>

單行註解僅僅註解到行末或者當前的 PHP 程式區段,看哪個首先出現。這意味著在 // ... ?> 或者 # ... ?> 之後的 HTML 碼將被顯示出來:?> 跳出了 PHP 模式並返回了 HTML 模式,//# 並不能影響到這一點。如果啟用了 asp_tags 設定選項,其行為和 // %># %> 相同。不過,</script> 標籤在單行註解中不會跳出 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 */
 
*/
?>