指令分离

就像大多数其他 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";