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 other words, 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 2003 (c) HerongYang.com. All Rights Reserved.
*/ ?>
I am tossing a coin now. Guess what the result will be?
<?php $coin = rand(0,1); ?>
<?php if ($coin==1) { ?>
   Head
<?php } else { ?>
   Tail
<?php } ?>

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

herong> \php\php HeadOrTail.php

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

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 2003 (c) HerongYang.com. 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";
} ?>

Table of Contents

 About This Book

 Introduction and Installation of PHP

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

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 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

 Managing File Upload

 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

 Parsing and Managing HTML Documents

 Configuring and Sending Out Emails

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 Archived Tutorials

 References

 Full Version in PDF/EPUB