PHP tags
When PHP parses a file, it looks for opening and closing tags, which are <?php
and ?>
which tell PHP to start and stop interpreting the code between them.
PHP also allows for short tags <?
and ?>
, which are discouraged because they are not always available.
Everything outside of a pair of opening and closing tags is ignored by the PHP parser which allows PHP files to have mixed content. This allows PHP to be embedded in HTML documents, for example to create templates.
There are four different pairs of opening and closing tags which can be used in PHP:
- Always available:
<?php ... ?>
<script language="php"> ... </script>
- Can be turned on and off from the php.ini configuration file:
<? ... ?>
: short tags.<% ... %>
: ASP style tags.
Instruction separation
As in C, C++, Java, JavaScript, or Perl, PHP requires instructions to be terminated with a semicolon ;
at the end of each statement.
Comments
PHP supports C, C++ (Java and JavaScript) and Unix shell-style (Perl style) comments:
//
: One line comment.#
: One line comment./* */
: Block comment, it is an error to nest these comments.