PHP Tags

PHPServer Side ProgrammingProgramming

Definition and Usage

A PHP code script is a text file having .php extension and is stored on web server. The PHP parser on server looks for special sequence of characters <?php and ?>. These are called PHP's opening and closing tags. Statements witihn these two are interpreted by the parser. PHP script within these tags can be embedded in HTML document, so that embedded code is executed on server, leaving rest of the document to be processed by client browser's HTML parser.

Syntax

<?php
//one or more PHP statements
..
..
?>

Short tags

PHP allows a using a shorter representation of opening tag <? instead of cannonical usage <?php if it s enabled in php.ini file by enabling short_open_tag in php.ini file

<?
//one or more PHP statements
..
..
?>

PHP Version

This setting is recommended to be Off for production environment. Use of ASP style tags <%, %> and <script language="PHP"> has been discontinued since PHP 7.0

Following example shows use of PHP tags

Example

 Live Demo

<?php
//cannonical PHP tags
echo "Hello World";
?>

Output

This will produce following result −

Hello World

PHP supports a short echo tag <?= which is equivalent to the more verbose <?php echo.

Example

 Live Demo

<?= "Hello World";
?>

Output

This will produce following result −

Hello World

Example using short tags

Example

 Live Demo

<?php
//set short_open_tag=on
echo "Hello World";
?>

Output

This will produce following result −

Hello World
raja
Published on 19-Sep-2020 17:49:48
Advertisements