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 <?php and 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 Style Tags

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

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

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: