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 <?php and ends with ?>
Types of Php Syntax:There are four different types of syntax or opening/closing tags used in php:
- Default Syntax
- Short Open Tags
- HTML Script Tags
- ASP Style Tags
Default Syntax: The default syntax starts with "<? php" and ends with "?>".
<?php 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."; </script>
ASP Style Tags: 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'; %>
PHP syntax is only used within PHP tags. It is also embedded in HTML and it can be used anywhere in the document.
<html> <head> <title> PHP Page</title> </head> <body> <?php echo "This is php page..."; ?> </body> </html>