PHP Script Processing Rules

This section describes the PHP script source code processing rules - all non-PHP text segments are converted into print statements and merged with PHP code segments to form a single code block.

As I mentioned in the previous section, a PHP script source code is a sequence non-PHP text segments and PHP code segments. The PHP engine will process the source code in 3 logical steps:

In anothe word, a PHP script source code can be viewed as a single PHP code block. All non-PHP text segments are just PHP print statements written in a special way.

PHP's processing rules are very similar to Active Server Page (ASP)'s processing rules.

Now let's see an example PHP script source code file:

<?php /* HeadOrTail.php
 - Copyright (c) 2015,, All Rights Reserved.
*/ ?>
I am tossing a coin now. Guess what the result will be? 
<?php $coin = rand(0,1); ?>
<?php if ($coin==1) { ?>
<?php } else { ?>
<?php } ?>

If you process this script with the PHP engine, you will get:

I am tossing a coin now. Guess what the result will be?

Based on the PHP engine processing rules, the above script is identical to this script from the PHP engine process point of view:

<?php /* HeadOrTailModified.php
 - Copyright (c) 2015,, All Rights Reserved.
print "I am tossing a coin now. Guess what the result will be?\n";
$coin = rand(0,1);  
if ($coin==1) { 
print "   Head\n";
} else { 
print "   Tail\n";
} ?>

Last update: 2015.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.0

PHP Script File Syntax

 PHP Script Source Code File Format

PHP Script Processing Rules

 PHP Statement Delimiter and Comments

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Configuring and Sending out Emails

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Outdated Tutorials


 PDF Printing Version