Web Programming with PHP

6 Basic Syntax

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:

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: