PHP Script Source Code File Format

This section describes the PHP script source code file format - A text file with PHP code segments mixed into non-PHP text. The most common way to mix PHP codes is to use the PHP processing tag '?php'.

Like any other scripting language, PHP is used to transform text information from an input to an output by mixing PHP code segments in the input text. This input of mixed PHP code and non-PHP text is called PHP script source code, which is usually stored as a text file.

Since multiple PHP code segments can be mixed with non-PHP text, a PHP script source code will look like this:

text PHP_code text PHP_code text PHP_code ...

When you ask the PHP to process a PHP script source code, it will separate PHP code segments from the non-PHP text using following 3 default rules:

1. PHP processing tag: <?php PHP_code ?> - Everything included in the "?php" tag will be processed as PHP code. For example:

Hello <?php
   $name = "Herong";
   echo $name;
?>
, Nice to meet you!

2. PHP processing tag shorthand: <? PHP_code ?> - Everything included in the "?" tag will be processed as PHP code. For example:

Hello <?
   $name = "Herong";
   echo $name;
?>
, Nice to meet you!

3. HTML "script" tag: <script language="php">PHP_code</script> - Everything between the "script" starting tag and the "script" ending tag will be processed as PHP code. For example:

Hello <script language="php">
   $name = "Herong";
   echo $name;
</script>
, Nice to meet you!

The PHP processing tag is the most commonly used way to mixed PHP codes into non-PHP text to create a PHP script source code file. Since most PHP scripts are designed to generate Web pages, non-PHP text in a PHP script source code is made of mostly HTML tags. Here is an example of a PHP script source code that generates a simple Web page:

<html>
<head>
<title>Welcome Page</title>
</head>
<body>
<p>
Hello <?php
   $name = "Herong";
   echo $name;
?>
, Nice to meet you!
</p>
</body>
</html>

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