Always Learning

Advanced Search

PHP 5 Unleashed

PHP 5 Unleashed

John Coggeshall

Jan 2005, Paperback, 840 pages
ISBN13: 9780672325113
ISBN10: 067232511X
This title is ordered on demand which may result in extended delivery times.
  • Print pagePrint page
  • Email this pageEmail page
  • Share

Over 12 million Internet domains worldwide use the PHP language to power their websites. If you are a programmer included in this group, or would like to be one, you should pick up a copy of PHP Unleashed. The definitive guide in PHP programming, PHP Unleashed thoroughly and authoritatively covers the release of PHP 5, as well as advanced topics not found in other books. It begins with a detailed summary of the basics and then quickly moves on to more advanced topics such as working with data, outputting graphical data and building complete applications. Whether you're an experienced programmer and new to PHP, or an experienced PHP programmer but new to PHP 5, this is the one PHP book you need in your library.

Over 12 million Internet domains worldwide use the PHP language to power their websites. If you are a programmer included in this group, or would like to be one, you should pick up a copy of PHP Unleashed. The definitive guide in PHP programming, PHP Unleashed thoroughly and authoritatively covers the release of PHP 5, as well as advanced topics not found in other books. It begins with a detailed summary of the basics and then quickly moves on to more advanced topics such as working with data, outputting graphical data and building complete applications. Whether you're an experienced programmer and new to PHP, or an experienced PHP programmer but new to PHP 5, this is the one PHP book you need in your library.


Organization of the Book


1. Basic PHP Development.

How PHP Scripts Work

Basic PHP Syntax

Basic PHP Data Types

Variable Manipulation

Control Structures

Logical Control Structures

Repetition Control Structures

Embedding Control Structures

User-Defined Functions

Dynamic Variables and Functions

Dynamic Variables

Dynamic Functions

Multiple File PHP Scripts


Variable References

References Used in Functions

Strings in PHP

Speed and Efficiency of String Expressions

Comparing Strings

Advanced String Comparison

Comparing Phrases

Search and Replacement

Replacing Strings

Formatting Strings

Alternatives to printf()

Strings and Locales

Formatting Currency Values

Formatting Date and Time Values


2. Arrays.

Basic Arrays

Array Syntax

Working with Arrays

Implementing Arrays

Using an Array as a List

Using Arrays as a Sortable Table

Using Arrays as a Lookup Table

Converting from Strings to Arrays and Back

More Array Materials

3. Regular Expressions.

The Basics of Regular Expressions

Limitations of the Basic Syntax

POSIX Regular Expressions

Perl-Compatible Regular Expressions (PCRE)

Named Patterns

PCRE Modifiers

A Few Final Words

4. Working with Forms in PHP.

HTML Forms 101

How Forms Are Created

HTML Widgets

Working with Form Submissions in PHP

Retrieving Form Values

Using Arrays as Widget Names

Handling File Uploads


5. Advanced Form Techniques.

Data Manipulation and Conversion

Dealing with Magic Quotes

Data Conversion and Encoding


Form Data Integrity

Securing Hidden Elements

The protect() Function

The validate() Function

Putting protect() and validate() into Action

Form Processing

Basic Form Processing and Validation

General-Purpose Form Validation

Separation of Presentation from Validation


6. Persistent Data Using Sessions and Cookies.

HTTP Cookies

Cookie Features and Restrictions

How Cookies Are Implemented

Implementing Cookies in Your Scripts

PHP Sessions

Basic Session Use

Session Propagation

Advanced Sessions

Custom Session Handling

Customizing Session Support


7. Using Templates.

The What and Why of Templates

Separating Common Elements from Code

A (Quick) Template System Example

The Smarty Template Engine

Installing Smarty

Basic Smarty: Variables and Modifiers

Configuration Files and Functions



8. PEAR.

What Is PEAR?

A Code Library

A Coding Standard

A System for Distribution and Maintenance

The PHP Foundation Classes

The PEAR Package Manager

A Diverse Community

Getting and Installing PEAR

On *NIX Systems

On Windows Systems

Through a Web Browser

Using the PEAR Package Manager

Listing Packages

Finding Packages

Installing and Upgrading Packages

Uninstalling Packages

Alternative Installation Methods

Using the PEAR Website

Browsing the Package List

Searching for a Package

Downloading and Installing a Package

Using PEAR Packages in Applications

Setting Up php.ini

Including the Package

Using Packages Not Installed Through pear



Mailing Lists/Newsgroups



9. XSLT and Other XML Concerns.

Relating XML to HTML

Using XSLT to Describe HTML Output Using XML Input

XSL Stylesheets

XSLT File Format Basics

Commonly Used XSLT Instructions

Using XSLT Instruction Elements with XSLT Patterns

Sample XML to HTML Transformation Using XSLT

PHP4 and XSLT Using the DOM XML Module

Sample Transformation Using PHP4 and DOM XML

DOM XML Functions and Properties of Note for XSLT Users

Including XSLT Support in PHP4 via DOM XML

PHP4 and XSLT Using the XSLT Module

Sample Transformation Using PHP4 and XSLT

XSLT Functions and Properties of Note

Including XSLT Support in PHP4 via XSLT


Sample Transformation Using PHP5

PHP5 Functions and Properties of Note for XSLT Users

Including XSL Support in PHP5

Accessing XML Data Using SimpleXML

Using SimpleXML in PHP Scripts

Additional Notes About SimpleXML in PHP Scripts

Generating XML Documents Using PHP

Functions and Properties for Storing XML Objects as Files



10. Debugging and Optimizations.

Debugging Your PHP Scripts

Syntax-Related Bugs

Logical Bugs

Optimizing Your PHP Scripts

The Secret to Finding Optimizations-Profiling

Common PHP Bottlenecks and Solutions


11. User Authentication.

Authenticating Users in PHP


Using HTTP Authentication with Apache

Using HTTP Authentication

Using PHP Sessions

Securing PHP Code


Maximum Error

Trust No One-Especially Not User Data

Printing User Data

Working with Files

Working with Databases


12. Data Encryption.

Shared Secret Versus Public Key

Shared Secret Algorithms

Phrase Substitution

Character Substitution

Taking It Further

Stronger Encryption Algorithms

Public Key Cryptography

The RSA Algorithm

Signing Versus Safeguarding

Man in the Middle

Using Public Keys in PHP

SSL Streams

Generating a Public Key Certificate and Private Key

Encrypting/Decrypting Data

Encrypting and Sending Secure Emails Using S/MIME


13. Object-Oriented Programming in PHP.

Why Objects?

Creating Basic Classes

Private, Protected, and Public

Constructors and Destructors

Class Constants

Static Methods

Class Inheritance

Advanced Classes

Abstract Classes and Methods


Final Classes and Methods

Special Methods

Getters and Setters

The __call() Method

The __toString() Method

Class Autoloading

Object Serialization


Understanding the Call Stack

The Exception Class

Throwing and Catching Exceptions



14. Error Handling.

The PHP Error-Handling Model

Error Types

What to Do About Errors

The Default Error Handler

Error Suppression

Custom Error Handlers

Causing Errors

Putting It All Together


15. Working with HTML/XHTML Using Tidy.


Basic Tidy Usage

Parsing Input and Retrieving Output

Cleaning and Repairing Documents

Identifying Problems Within Documents

Tidy Configuration Options

Tidy Options at Runtime

Tidy Configuration Files

Using the Tidy Parser

How Documents Are Stored in Tidy

The Tidy Node

Applications of Tidy

Tidy as an Output Buffer

Converting Documents to CSS

Reducing Bandwidth Usage

Beautifying Documents

Extracting URLs from a Document


16. Writing Email in PHP.

The MIME Protocol

Implementing MIME Email in PHP

The MIMEContainer and MIMESubcontainer Classes

The MIMEAttachment, MIMEContent, and MIMEMessage Classes



17. Using PHP for Console Scripting.

Core CLI Differences

Working with PHP CLI

Command-Line Arguments and Return Codes

CLI Tools and Extensions

The Readline Extension

Creating User Interfaces


18. SOAP and PHP.

What Are Web Services?

Transport with SOAP

Description with WSDL

Directory Lookup with UDDI


Creating Web Services

Consuming Web Services

Looking for Web Services


19. Building WAP-Enabled Websites.

What Is WAP?

System Requirements

Nokia Mobile Internet Toolkit

Ericsson WapIDE

Openwave SDK

Motorola Wireless IDE/SDK

Introduction to WML

WML Structure




WML Forms

Serving WAP Content

MIME Types

Web Server Configuration

Setting MIME Type from PHP

Client Detection

Displaying Graphics

Sample Applications

Server-Side Form Data Processing

WAP Cinema Reservation System



20. Working with the File System.

Working with Files in PHP

Reading and Writing Text Files

Reading and Writing Binary Files

Working with Directories in PHP

File Permissions

How Unix Permissions Work

Working with Permissions from PHP

File Access Support Functions

Logic Functions

File Manipulation

Specialized File Access


21. Network I/O.

DNS/Reverse DNS Lookups

Retrieving the DNS Record by IP

Retrieving IP Addresses Based on Hostname

Determining DNS Record Information

Socket Programming

Socket Basics

Creating a New Socket

Dealing with Socket Errors

Creating Client Sockets

Creating Server Sockets

Working with Multiple Sockets at Once

Network Helper Functions


22. Accessing the Underlying OS from PHP.


Unix-Specific OS Functionality

Direct Input and Output (I/O)

PHP POSIX Functions

Unix Process Control

Platform-Independent System Functions

Executing Applications from PHP

Basic External Application Execution

Single-Direction External Command Pipes

Dealing with the System Environment

A Brief Note About Security



23. Introduction to Databases.

Using the MySQL Client

Basic MySQL Usage

RDBMS Fundamentals

Performing Queries Using SQL


24. Using MySQL with PHP.

Performing Queries from PHP

MySQLi Basics

Executing Multiple Queries

Creating a Visitor-Tracking System

Prepared Statements


A MySQLi Session Handler

What Is a Custom Session Handler?

Defining Your Own Session Handler

The MySQLi Session Handler


25. Using SQLite with PHP.

What Makes SQLite Unique?

General Differences Between SQLite and MySQL

How SQLite Deals with Textual and Numeric Types

How SQLite Treats NULL Values

Accessing a Database from Multiple Processes

Basic SQLite Functionality

Opening and Closing Databases

Performing Queries

Retrieving Results

Handling Errors

Navigating Resultsets

Working with PHP UDFs in SQLite

Calling PHP Functions in SQL Queries

Odds and Ends


26. PHP's dba Functions.

Preparations and Settings

Creating a File-Based Database

Writing Data

Reading Data

Sample Application



27. Working with Images.

Basic Image Creation Using GD

Retrieving Image information

Using the PHP/GD Drawing Functions

Drawing Line-Based Geometric Shapes

Drawing Curved Surfaces

Filled Shapes and Image Functions

Working with Colors and Brushes

Working with the Image Palette

Drawing Using Brushes

Using Fonts and Printing Strings

Using GD's Internal Fonts

Using TrueType Fonts

Using Postscript Type 1

General Image Manipulation

Copying One Image to Another

Other Graphics Functions

EXIF Functions


28. Printable Document Generation.

A Note Regarding the Examples in This Part

Generating Dynamic RTF Documents

Generating Dynamic PDF Documents

The PDFLib Coordinate System

Using PDFLib Configuration Parameters

Generating PDF Documents from Scratch

Related Resources


Appendix A. Installing PHP5 and MySQL.

Installing PHP5



Mac OS X

Installing MySQL and PHP Modules



Installing PEAR

Appendix B. HTTP Reference.

What Is HTTP?

PHP Programming Libraries for HTTP Work

Understanding an HTTP Transaction

HTTP Client Methods

What Comes Back: Server Response Codes

HTTP Headers


Identifying Clients and Servers

The "Referer"

Fetching Content from an HTTP Source

Media Types

Cookies: Preserving State and a Tasty Treat

Security and Authorization

Client-Side Caching of HTTP Content

Appendix C. Migrating Applications from PHP4 to PHP5.


Object-Oriented Programming (OOP)

New Behavior of Functions

Further Reading

Appendix D. Good Programming Techniques and Performance Issues.

Common Style Mistakes

Configuration Directives

PHP Is Forgiving, to a Fault

Reinventing the Wheel

Variables-Use Them, Don't Abuse Them

Common Security Concerns

Unintended Consequences

System Calls

Preventing System Call Attacks

Securing File Uploads

Style and Security-Logging

Logging Custom Error Messages


Appendix E. Resources and Mailing Lists.

Relevant Websites

Mailing Lists and Newsgroups


  • Practical, example-rich introduction to Web programming with PHP—Covers all the fundamentals: file system manipulation, strings, arrays, regular expressions, forms, sessions, cookies, and much more.
    • Thoroughly prepares students to create the Web applications that represent PHPs primary area of usage.

  • Detailed introduction to PHP 5 object-oriented programming—Fully reflects PHP 5s major object-oriented improvements.
    • Helps students use the object-oriented techniques that will increasingly dominate PHP programming.

  • Complete section on PHPs e-mail features—Includes full chapters on accessing IMAP mail servers, writing MIME email in PHP, and accessing NNTP news servers.
    • Teaches students how to use PHP to automate a wide range of real-world e-mail tasks for business and other environments.

  • Start-to-finish coverage of data access, including XML-based techniques—Covers everything from basic database access to XML parsing, SOAP, and XSLT.
    • Teaches students how to build powerful Web applications and services that leverage data from virtually any source.

  • Advanced coverage—Contains detailed coverage that experienced PHP programmers have been searching for, including chapters on wireless applications and COM integration.
    • Grows with students to help them accomplish complex leading-edge tasks with PHP.

PHP 5 Unleashed Lead Author

John Coggeshall is a Technical Consultant for Zend Technologies where he provides professional services to clients around the world. He got started with PHP in 1997 and is the author of two published books and over 100 articles on PHP technologies with some of the biggest names in the industry such as Sams Publishing, Apress and O'Reilly. John also is a active contributor to the PHP core as the author of the tidy extension, a member of the Zend Education Advisory Board, and frequent speaker at PHP-related conferences worldwide. His web site, is an excellent resource for any PHP developer.

Contributing Authors

Christian Wenz is author or coauthor of more than three dozen books. He specializes in Web technologies, with focus on Web scripting languages and Web services. He frequently writes for IT magazines and speaks at national and international conferences. Christian maintains or co-maintains several PEAR packages and is Germany's very first Zend Certified Engineer. Christian contributed eight chapters to PHP 5 Unleashed. He lives and works in Munich, Germany.

Sara Golemon is an application developer at the University of California at Berkeley as well as a contributor to the PHP project and other Open Source applications. She helps maintain the PHP streams layer and miscellaneous core extensions and has made more than 400 individual contributions to the online manual, authoring entire reference sections and appendixes. Sara is also the lead developer of nine PECL extensions, including Runkit, Classkit, Parsekit, OggVorbis, and OpenAL.

J. Scott Johnson is the founder of, a leading provider of XML Search Services. He is also the founder of NTERGAID, Inc., and was previous Vice President of Engineering for Mascot, Network. He is a leading blogger, author, and software developer.

Ben Ramsey is a Technology Manager for Hands On Network, an international, non-profit volunteer organization based in Atlanta, Georgia. Before his move to the non-profit sector, he worked for four years as the Technology Director for Roswell, Georgia-based EUREKA! Interactive, Inc. With EUREKA!, he served as the software architect and lead programmer of numerous Web-based applications for local governments and small businesses. He is a Zend Certified Engineer and co-founder of Atlanta PHP.

Marco Tabini is the publisher of php|architect (, the premier magazine for PHP professionals, and has worked on websites for clients ranging from small startup operations to the Fortune 500s. Despite having been an IT industry professional for the last 15 years, he still manages to maintain a reasonable level of sanity–at least most of the time.

Aron Hsiao is a Linux enthusiast with over a decade of administrative Unix experience. He has worked in various capacities in network deployment, in software and web development, and in the online retail industry. He served as the guide to Linux from 1997 through 2001 and holds a Masters degree in the Social Sciences from the University of Chicago. He is the author of The Concise Guide to XFree86 for Linux, Sams Teach Yourself Red Hat Desktop All In One, and other popular Linux titles.

© Copyright Pearson Education. All rights reserved.