同 c 或 perl 一样,php 需要在每个语句后用分号结束指令。一段 php 代码中的结束标记隐含表示了一个分号;在一个 php 代码段中的最后一行可以不用分号结束。如果后面还有新行,则代码段的结束标记包含了行结束。
<?php
echo "This is a test" ;
?><?php echo "This is a test" ?>
<?php echo 'We omitted the last closing tag' ;
文件末尾的 PHP 代码段结束标记可以不要,有些情况下当使用 include 或者 require 时省略掉会更好些,这样不期望的空白符就不会出现在文件末尾,之后仍然可以输出响应标头。在使用输出缓冲时也很便利,就不会看到由包含文件生成的不期望的空白符。
束标记(?>)同样隐含语句的结束,因此下面的代码是等价的
<?php echo "This is a text"; ?>
<?php echo "This is a test"?>
注释:
php支持'c',c++和unix shell风格的注释;例如:
立即学习“PHP免费学习笔记(深入)”;
<?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 ?>
"单行"注释仅仅注释到行末或者当前的代码块,视乎哪个首先出现。
<h1>This is an <?php # echo "simple"?>example.</h1> <p>The header above will say 'This is an example'.
小心不要嵌套'C'风格的注释,当注释大量的代码时,可能犯该错误。
<?php /* echo "This is a test";/*This comment will cause a problem*/ */ ?>
单行注释仅仅注释到行末或者当前的php代码块
以上就是php指令分隔符的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号