php指令分隔符

怪我咯
怪我咯 原创
2023-03-10 15:34:02 1961浏览

同 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
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中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。