PHP Programing language

PHP Syntax
Previous Home Next

Syntax in PHP

PHP's syntax and semantics are similar to most other programming languages (C, Java, Perl) with the addition that all PHP code is contained with a tag, of sorts.

A PHP script can be placed anywhere in the document. A PHP script starts with<?phpand ends with?>

Types of Php Syntax:

There are four different types of syntax or opening/closing tags used in php:
  1. Default Syntax
  2. Short Open Tags
  3. HTML Script Tags
  4. ASP StyleTags

Default Syntax: The default syntax starts with "<? php" and ends with "?>".


echo "Default Syntax";  

Short Open Tags: The short tags starts with "<?" and ends with "?>". These tags are only used when they are enabled in php.ini configuration file on servers.


echo "short tags";

HTML Script Tags: Script is effective to solve escape situation which comes in some editors like Front Page editor


<script language="php">  
echo "HTML Script Tag.";  

ASP StyleTags: The ASP style tags starts with "<%" and ends with "%>". It mimic the tags used by Active Server Pages to delineate code blocks. ASP style tags are only available when they are enabled via the asp_tags php.ini configuration file directive.


echo'This is ASP like style';
Combination of PHP and HTML

PHP syntax is only used within PHP tags. It is also embedded in HTML and it can be used anywhere in the document.


<title> PHP Page</title>
echo "This is php page...";


This is php page...
Previous Home Next