PHP Programing language

PHP Syntax
Previous Home Next
adplus-dvertising

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 "?>".

Example:

<?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.

Example:

<?
echo "short tags";
?>

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

Example:

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

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.

Example:

<%
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.

Example:

<html>
<head>
<title> PHP Page</title>
</head>
<body>
<?php
echo "This is php page...";
?> 
</body>
</html>

Output:

This is php page...
Previous Home Next