Chapter 5. Syntax and grammar

Table of Contents
Escaping from HTML
Instruction separation
Variable types
Variable initialization
Variable Scope
Variable variables
Variables from outside PHP
Type juggling
Array manipulation

PHP's syntax is borrowed primarily from C. Java and Perl have also influenced the syntax.

Escaping from HTML

There are three ways of escaping from HTML and entering "PHP code mode":

Example 5-1. Ways of escaping from HTML

1.  <? echo("this is the simplest, an SGML processing instruction\n"); ?>

2.  <?php echo("if you want to serve XML documents, do like this\n"); ?>

3.  <script language="php"> 
        echo ("some editors (like FrontPage) don't
               like processing instructions");
    </script>;

4.  <% echo("As of PHP 3.0.4 you may optionally use ASP-style tags"); %>