PHP Getting started with PHP PHP Tags

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

There are three kinds of tags to denote PHP blocks in a file. The PHP parser is looking for the opening and (if present) closing tags to delimit the code to interpret.

Standard Tags

These tags are the standard method to embed PHP code in a file.

<?php
    echo "Hello World";
?>
PHP 5.x5.4

Echo Tags

These tags are available in all PHP versions, and since PHP 5.4 are always enabled. In previous versions, echo tags could only be enabled in conjunction with short tags.

<?= "Hello World" ?>

Short Tags

You can disable or enable these tags with the option short_open_tag.

<?
    echo "Hello World";
?>

Short tags:

  • are disallowed in all major PHP coding standards
  • are discouraged in the official documentation
  • are disabled by default in most distributions
  • interfere with inline XML's processing instructions
  • are not accepted in code submissions by most open source projects
PHP 5.x5.6

ASP Tags

By enabling the asp_tags option, ASP-style tags can be used.

<%
    echo "Hello World";
%>

These are an historic quirk and should never be used. They were removed in PHP 7.0.



Got any PHP Question?