- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP Tags
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
<?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
<?= "Hello World"; ?>
Output
This will produce following result −
Hello World
Example using short tags
Example
<?php //set short_open_tag=on echo "Hello World"; ?>
Output
This will produce following result −
Hello World