Tuesday, 18 December 2012

PHP Basics - PHP Tags

Every PHP scripy in your file should start with PHP Opening Tag, End end with an PHP Closing Tag,
Following are standard tags for opening and closing tags in PHP.
<?php
is standard tag for opening PHP script and
?>
is standard tag for closing PHP script.
Your PHP file should look like this.



   1: <?php


   2:  


   3:     //Your code goes here


   4:  


   5: ?>
From the above example you can write your PHP script in between Opening and closing tags.
Apart from standard tags PHP allows you to use other style of tags, you need to enable it in your PHP settings file i.e. php.ini.
You can use short tags of PHP (need to enable short tags in php.ini file)



   1: <? //opening tag

   2:  

   3:     //code goes here

   4:  

   5: ?>  //closing tag

Every PHP code line must end with a semicolon “ ; “ , So that PHP interpreter can be able to differentiate  code lines from each other and gives us a proper output.


   1: <?php

   2:     

   3:     echo "Hello World";

   4:  

   5: ?>

If the file is pure PHP file ( No HTML added to the file) you can omit the PHP closing tag an the end of file.





No comments:

Post a Comment