29 September 2013

How does code is separated in PHP?

  • PHP requires instructions to be terminated with a semicolon at the end of each statement. 
  • The closing tag (?>) of a block of PHP code automatically implies a semicolon(;) 
  • (Ref-Example 2), so you do not need to have a semicolon terminating the last line of a PHP block.
  • Example 1:
1
2
3
4
5
6
7
<?php

        echo 'This is a test';

        echo 'This is another test';

    ?>
  • Example 2:
1
<?php echo 'This is a test' ?>
  • Example 3:
1
<?php echo 'We omitted the last closing tag'; 
  • Note: The closing tag of a PHP block at the end of a file is optional and in some cases omitting it is helpful when using include() or require(), 
  • So unwanted white space will not occur at the end of files, and you will still be able to add headers to the response later.
Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

No comments:

Post a Comment

Featured Post

How to Write PHP code and HTML code within a same file

A PHP file can have both PHP code and HTML code together. Any HTML code written outside of PHP <?php //php code here… ?> Code is ig...

Popular Posts