Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to use PHP tags

Dario Vincenzo Tarantini

PHP is an interpreted language, so each time we request a web page, the interpreter searches for each PHP tag and executes the code inside it.

These tags are:

  • <?php ... ?>
  • <? ... ?>
  • <?= ... ?>

When our application contains only PHP code, we can omit the ?> end tag. This prevents new lines from being added or accidental whitespaces after the PHP closing tag.

What is <?php?

This is the most common PHP tag. It is used almost everywhere and is used to initialize a PHP code section.

Here is a basic example:

<?php // this tells PHP that the code starts here
echo 'Hello, Educative!';
/* here it ends */ ?>

What is <??

<? is a short-form for <?php and is termed as “short tag”.
It has the same utility as the <?php tag but its use should be avoided due to compatibility issues. This is because short tags can only be used if they are enabled.

Note: these tags can be disabled in php.ini via

Here is an example of using short tags:

echo 'Hello, Educative!';

What is <?=?

<?= is an alias of <?php echo.
It is a short form that is useful when we need to print something without writing everything each time.

<?= 'Hello, Educative!' ?>

Note: we also omitted the ; at the end of the string.




Dario Vincenzo Tarantini

View all Courses

Keep Exploring