<?php ?> usually is the open and
closing tags for PHP.
When PHP parses a file, it looks for opening
and closing tags, which tell PHP to start and stop interpreting
the code between them.
Parsing in this manner allows php to be embedded
in all sorts of different documents, as everything outside of
a pair of opening and closing tags is ignored by the PHP parser.
Most of the time you will see php embedded in HTML documents, as
in this example.
<p>This is going to be ignored.</p>
<?php echo 'While this is going to be parsed.'; ?>
<p>This will also be ignored.</p>
There are four different pairs of opening and closing tags which
can be used in php.
Two of those, <?php ?> and <script language="php"> </script>,
are always available. The other two are short tags and ASP style
tags, and can be turned on and off from the php.ini configuration
file. As such, while some people find short tags and ASP style tags
convenient, they are less portable, and generally not recommended.
Note: Also note that if you are embedding PHP within XML or XHTML
you will need to use the <?php ?> tags to remain compliant
PHP Opening and Closing Tags
- <?php echo 'if you want to serve XHTML or XML documents,
do like this'; ?>
- <script language="php">
echo 'some editors (like FrontPage) don\'t
like processing instructions';
- <? echo 'this is the simplest, an SGML processing instruction';
<?= expression ?> This is a shortcut for "<? echo expression ?>"
- <% echo 'You may optionally use ASP-style tags'; %>
<%= $variable; # This is a shortcut for "<% echo . . ." %>
The example one is the most commonly used, and recommended PHP tags.