指令分離

就像大多數其他 C 風格的語言一樣,每個語句都以分號結束。此外,結束標記用於終止 PHP 塊的最後一行程式碼。

如果 PHP 程式碼的最後一行以分號結尾,則如果最後一行程式碼後面沒有程式碼,則結束標記是可選的。例如,我們可以在以下示例中省略 echo "No error"; 之後的結束標記:

<?php echo "No error"; // no closing tag is needed as long as there is no code below

但是,如果 PHP 程式碼塊後面有任何其他程式碼,則結束標記不再是可選的:

<?php echo "This will cause an error if you leave out the closing tag"; ?>
<html>
    <body>
    </body>
</html>

如果該程式碼塊具有結束標記,我們也可以省略 PHP 程式碼塊中最後一個語句的分號:

<?php echo "I hope this helps! :D";
echo "No error" ?>      

通常建議始終使用分號並對除最後一個 PHP 程式碼塊之外的每個 PHP 程式碼塊使用結束標記,如果該程式碼塊後面沒有更多程式碼。

所以,你的程式碼基本上應該是這樣的:

<?php
    echo "Here we use a semicolon!";
    echo "Here as well!";
    echo "Here as well!";
    echo "Here we use a semicolon and a closing tag because more code follows";
?>
<p>Some HTML code goes here</p>
<?php
    echo "Here we use a semicolon!";
    echo "Here as well!";
    echo "Here as well!";
    echo "Here we use a semicolon and a closing tag because more code follows";
?>
<p>Some HTML code goes here</p>
<?php
    echo "Here we use a semicolon!";
    echo "Here as well!";
    echo "Here as well!";
    echo "Here we use a semicolon but leave out the closing tag";