Books & Videos

Table of Contents

  1. Chapter 1 Strings

    1. Introduction

    2. Accessing Substrings

    3. Extracting Substrings

    4. Replacing Substrings

    5. Processing a String One Byte at a Time

    6. Reversing a String by Word or Byte

    7. Expanding and Compressing Tabs

    8. Controlling Case

    9. Interpolating Functions and Expressions Within Strings

    10. Trimming Blanks from a String

    11. Generating Comma-Separated Data

    12. Parsing Comma-Separated Data

    13. Generating Fixed-Width Field Data Records

    14. Parsing Fixed-Width Field Data Records

    15. Taking Strings Apart

    16. Wrapping Text at a Certain Line Length

    17. Storing Binary Data in Strings

    18. Program: Downloadable CSV File

  2. Chapter 2 Numbers

    1. Introduction

    2. Checking Whether a Variable Contains a Valid Number

    3. Comparing Floating-Point Numbers

    4. Rounding Floating-Point Numbers

    5. Operating on a Series of Integers

    6. Generating Random Numbers Within a Range

    7. Generating Biased Random Numbers

    8. Taking Logarithms

    9. Calculating Exponents

    10. Formatting Numbers

    11. Formatting Monetary Values

    12. Printing Correct Plurals

    13. Calculating Trigonometric Functions

    14. Doing Trigonometry in Degrees, Not Radians

    15. Handling Very Large or Very Small Numbers

    16. Converting Between Bases

    17. Calculating Using Numbers in Bases Other Than Decimal

    18. Finding the Distance Between Two Places

  3. Chapter 3 Dates and Times

    1. Introduction

    2. Finding the Current Date and Time

    3. Converting Time and Date Parts to an Epoch Timestamp

    4. Converting an Epoch Timestamp to Time and Date Parts

    5. Printing a Date or Time in a Specified Format

    6. Finding the Difference of Two Dates

    7. Finding the Difference of Two Dates with Julian Days

    8. Finding the Day in a Week, Month, or Year

    9. Validating a Date

    10. Parsing Dates and Times from Strings

    11. Adding to or Subtracting from a Date

    12. Calculating Time with Time Zones

    13. Accounting for Daylight Savings Time

    14. Generating a High-Precision Time

    15. Generating Time Ranges

    16. Using Non-Gregorian Calendars

    17. Using Dates Outside the Range of an Epoch Timestamp

    18. Program: Calendar

  4. Chapter 4 Arrays

    1. Introduction

    2. Specifying an Array Not Beginning at Element 0

    3. Storing Multiple Elements Per Key in an Array

    4. Initializing an Array to a Range of Integers

    5. Iterating Through an Array

    6. Deleting Elements from an Array

    7. Changing Array Size

    8. Appending One Array to Another

    9. Turning an Array into a String

    10. Printing an Array with Commas

    11. Checking if a Key Is in an Array

    12. Checking if an Element Is in an Array

    13. Finding the Position of a Value in an Array

    14. Finding Elements That Pass a Certain Test

    15. Finding the Largest or Smallest Valued Element in an Array

    16. Reversing an Array

    17. Sorting an Array

    18. Sorting an Array by a Computable Field

    19. Sorting Multiple Arrays

    20. Sorting an Array Using a Method Instead of a Function

    21. Randomizing an Array

    22. Removing Duplicate Elements from an Array

    23. Applying a Function to Each Element in an Array

    24. Finding the Union, Intersection, or Difference of Two Arrays

    25. Making an Object Act like an Array

    26. Program: Printing a Horizontally Columned HTML Table

  5. Chapter 5 Variables

    1. Introduction

    2. Avoiding == Versus = Confusion

    3. Establishing a Default Value

    4. Exchanging Values Without Using Temporary Variables

    5. Creating a Dynamic Variable Name

    6. Using Static Variables

    7. Sharing Variables Between Processes

    8. Encapsulating Complex Data Types in a String

    9. Dumping Variable Contents as Strings

  6. Chapter 6 Functions

    1. Introduction

    2. Accessing Function Parameters

    3. Setting Default Values for Function Parameters

    4. Passing Values by Reference

    5. Using Named Parameters

    6. Creating Functions That Take a Variable Number of Arguments

    7. Returning Values by Reference

    8. Returning More Than One Value

    9. Skipping Selected Return Values

    10. Returning Failure

    11. Calling Variable Functions

    12. Accessing a Global Variable Inside a Function

    13. Creating Dynamic Functions

  7. Chapter 7 Classes and Objects

    1. Introduction

    2. Instantiating Objects

    3. Defining Object Constructors

    4. Defining Object Destructors

    5. Implementing Access Control

    6. Preventing Changes to Classes and Methods

    7. Defining Object Stringification

    8. Specifying Interfaces

    9. Creating Abstract Base Classes

    10. Assigning Object References

    11. Cloning Objects

    12. Overriding Property Accesses

    13. Calling Methods on an Object Returned by Another Method

    14. Aggregating Objects

    15. Accessing Overridden Methods

    16. Using Method Polymorphism

    17. Defining Class Constants

    18. Defining Static Properties and Methods

    19. Controlling Object Serialization

    20. Introspecting Objects

    21. Checking if an Object Is an Instance of a Specific Class

    22. Autoloading Class Files upon Object Instantiation

    23. Instantiating an Object Dynamically

    24. Program: whereis

  8. Chapter 8 Web Basics

    1. Introduction

    2. Setting Cookies

    3. Reading Cookie Values

    4. Deleting Cookies

    5. Redirecting to a Different Location

    6. Detecting Different Browsers

    7. Building a Query String

    8. Reading the Post Request Body

    9. Generating HTML Tables with Alternating Row Styles

    10. Using HTTP Basic or Digest Authentication

    11. Using Cookie Authentication

    12. Flushing Output to the Browser

    13. Buffering Output to the Browser

    14. Compressing Web Output

    15. Reading Environment Variables

    16. Setting Environment Variables

    17. Communicating Within Apache

    18. Program: Web Site Account (De)activator

    19. Program: Tiny Wiki

  9. Chapter 9 Form

    1. Introduction

    2. Processing Form Input

    3. Validating Form Input: Required Fields

    4. Validating Form Input: Numbers

    5. Validating Form Input: Email Addresses

    6. Validating Form Input: Drop-Down Menus

    7. Validating Form Input: Radio Buttons

    8. Validating Form Input: Checkboxes

    9. Validating Form Input: Dates and Times

    10. Validating Form Input: Credit Cards

    11. Preventing Cross-Site Scripting

    12. Working with Multipage Forms

    13. Redisplaying Forms with Inline Error Messages

    14. Guarding Against Multiple Submission of the Same Form

    15. Processing Uploaded Files

    16. Preventing Global Variable Injection

    17. Handling Remote Variables with Periods in Their Names

    18. Using Form Elements with Multiple Options

    19. Creating Drop-Down Menus Based on the Current Date

  10. Chapter 10 Database Access

    1. Introduction

    2. Using DBM Databases

    3. Using an SQLite Database

    4. Connecting to an SQL Database

    5. Querying an SQL Database

    6. Retrieving Rows Without a Loop

    7. Modifying Data in an SQL Database

    8. Repeating Queries Efficiently

    9. Finding the Number of Rows Returned by a Query

    10. Escaping Quotes

    11. Logging Debugging Information and Errors

    12. Creating Unique Identifiers

    13. Building Queries Programmatically

    14. Making Paginated Links for a Series of Records

    15. Caching Queries and Results

    16. Accessing a Database Connection Anywhere in Your Program

    17. Program: Storing a Threaded Message Board

  11. Chapter 11 Sessions and Data Persistence

    1. Introduction

    2. Using Session Tracking

    3. Preventing Session Hijacking

    4. Preventing Session Fixation

    5. Storing Sessions in a Database

    6. Storing Sessions in Shared Memory

    7. Storing Arbitrary Data in Shared Memory

    8. Caching Calculated Results in Summary Tables

  12. Chapter 12 XML

    1. Introduction

    2. Generating XML as a String

    3. Generating XML with the DOM

    4. Parsing Basic XML Documents

    5. Parsing Complex XML Documents

    6. Parsing Large XML Documents

    7. Extracting Information Using XPath

    8. Transforming XML with XSLT

    9. Setting XSLT Parameters from PHP

    10. Calling PHP Functions from XSLT Stylesheets

    11. Validating XML Documents

    12. Handling Content Encoding

    13. Reading RSS and Atom Feeds

    14. Writing RSS Feeds

    15. Writing Atom Feeds

  13. Chapter 13 Web Automation

    1. Introduction

    2. Fetching a URL with the Get Method

    3. Fetching a URL with the Post Method

    4. Fetching a URL with Cookies

    5. Fetching a URL with Arbitrary Headers

    6. Fetching a URL with an Arbitrary Method

    7. Fetching a URL with a Timeout

    8. Fetching an HTTPS URL

    9. Debugging the Raw HTTP Exchange

    10. Marking Up a Web Page

    11. Cleaning Up Broken or Nonstandard HTML

    12. Extracting Links from an HTML File

    13. Converting Plain Text to HTML

    14. Converting HTML to Plain Text

    15. Removing HTML and PHP Tags

    16. Responding to an Ajax Request

    17. Integrating with JavaScript

    18. Program: Finding Stale Links

    19. Program: Finding Fresh Links

  14. Chapter 14 Consuming Web Services

    1. Introduction

    2. Calling a REST Method

    3. Calling a SOAP Method with WSDL

    4. Calling a SOAP Method Without WSDL

    5. Debugging SOAP Requests

    6. Using Complex SOAP Types

    7. Setting SOAP Types

    8. Using SOAP Headers

    9. Using Authentication with SOAP

    10. Redefining an Endpoint

    11. Catching SOAP Faults

    12. Mapping XML Schema Data Types to PHP Classes

    13. Calling an XML-RPC Method

    14. Using Authentication with XML-RPC

  15. Chapter 15 Building Web Services

    1. Introduction

    2. Serving a REST Method

    3. Serving a SOAP Method

    4. Accepting Arguments in a SOAP Method

    5. Generating WSDL Automatically

    6. Throwing SOAP Faults

    7. Processing a SOAP Header

    8. Generating a SOAP Header

    9. Using Authentication with SOAP

    10. Serving an XML-RPC Method

  16. Chapter 16 Internet Services

    1. Introduction

    2. Sending Mail

    3. Sending MIME Mail

    4. Reading Mail with IMAP or POP3

    5. Posting Messages to Usenet Newsgroups

    6. Reading Usenet News Messages

    7. Getting and Putting Files with FTP

    8. Looking Up Addresses with LDAP

    9. Using LDAP for User Authentication

    10. Performing DNS Lookups

    11. Checking if a Host Is Alive

    12. Getting Information About a Domain Name

  17. Chapter 17 Graphics

    1. Introduction

    2. Drawing Lines, Rectangles, and Polygons

    3. Drawing Arcs, Ellipses, and Circles

    4. Drawing with Patterned Lines

    5. Drawing Text

    6. Drawing Centered Text

    7. Building Dynamic Images

    8. Getting and Setting a Transparent Color

    9. Reading EXIF Data

    10. Serving Images Securely

    11. Program: Generating Bar Charts from Poll Results

  18. Chapter 18 Security and Encryption

    1. Introduction

    2. Preventing Session Fixation

    3. Protecting Against Form Spoofing

    4. Ensuring Input Is Filtered

    5. Avoiding Cross-Site Scripting

    6. Eliminating SQL Injection

    7. Keeping Passwords Out of Your Site Files

    8. Storing Passwords

    9. Dealing with Lost Passwords

    10. Verifying Data with Hashes

    11. Encrypting and Decrypting Data

    12. Storing Encrypted Data in a File or Database

    13. Sharing Encrypted Data with Another Web Site

    14. Detecting SSL

    15. Encrypting Email with GPG

  19. Chapter 19 Internationalization and Localization

    1. Introduction

    2. Listing Available Locales

    3. Using a Particular Locale

    4. Setting the Default Locale

    5. Localizing Text Messages

    6. Localizing Dates and Times

    7. Localizing Currency Values

    8. Localizing Images

    9. Localizing Included Files

    10. Managing Localization Resources

    11. Using gettext

    12. Setting the Character Encoding of Outgoing Data

    13. Setting the Character Encoding of Incoming Data

    14. Manipulating UTF-8 Text

  20. Chapter 20 Error Handling, Debugging, and Testing

    1. Introduction

    2. Finding and Fixing Parse Errors

    3. Creating Your Own Exception Classes

    4. Printing a Stack Trace

    5. Reading Configuration Variables

    6. Setting Configuration Variables

    7. Hiding Error Messages from Users

    8. Tuning Error Handling

    9. Using a Custom Error Handler

    10. Logging Errors

    11. Eliminating “headers already sent” Errors

    12. Logging Debugging Information

    13. Using a Debugger Extension

    14. Writing a Unit Test

    15. Writing a Unit Test Suite

    16. Applying a Unit Test to a Web Page

    17. Setting Up a Test Environment

  21. Chapter 21 Performance Tuning and Load Testing

    1. Introduction

    2. Timing Function Execution

    3. Timing Program Execution

    4. Profiling with a Debugger Extension

    5. Stress Testing Your Web Site

    6. Avoiding Regular Expressions

    7. Using an Accelerator

  22. Chapter 22 Regular Expressions

    1. Introduction

    2. Switching from ereg to preg

    3. Matching Words

    4. Finding the nth Occurrence of a Match

    5. Choosing Greedy or Nongreedy Matches

    6. Finding All Lines in a File That Match a Pattern

    7. Capturing Text Inside HTML Tags

    8. Preventing Parentheses from Capturing Text

    9. Escaping Special Characters in a Regular Expression

    10. Reading Records with a Pattern Separator

    11. Using a PHP Function in a Regular Expression

  23. Chapter 23 Files

    1. Introduction

    2. Creating or Opening a Local File

    3. Creating a Temporary File

    4. Opening a Remote File

    5. Reading from Standard Input

    6. Reading a File into a String

    7. Counting Lines, Paragraphs, or Records in a File

    8. Processing Every Word in a File

    9. Picking a Random Line from a File

    10. Randomizing All Lines in a File

    11. Processing Variable-Length Text Fields

    12. Reading Configuration Files

    13. Modifying a File in Place Without a Temporary File

    14. Flushing Output to a File

    15. Writing to Standard Output

    16. Writing to Many Filehandles Simultaneously

    17. Escaping Shell Metacharacters

    18. Passing Input to a Program

    19. Reading Standard Output from a Program

    20. Reading Standard Error from a Program

    21. Locking a File

    22. Reading and Writing Custom File Types

    23. Reading and Writing Compressed Files

  24. Chapter 24 Directories

    1. Introduction

    2. Getting and Setting File Timestamps

    3. Getting File Information

    4. Changing File Permissions or Ownership

    5. Splitting a Filename into Its Component Parts

    6. Deleting a File

    7. Copying or Moving a File

    8. Processing All Files in a Directory

    9. Getting a List of Filenames Matching a Pattern

    10. Processing All Files in a Directory Recursively

    11. Making New Directories

    12. Removing a Directory and Its Contents

    13. Program: Web Server Directory Listing

    14. Program: Site Search

  25. Chapter 25 Command-Line PHP

    1. Introduction

    2. Parsing Program Arguments

    3. Parsing Program Arguments with getopt

    4. Reading from the Keyboard

    5. Running PHP Code on Every Line of an Input File

    6. Reading Passwords

    7. Program: Command Shell

  26. Chapter 26 PEAR and PECL

    1. Introduction

    2. Using the PEAR Installer

    3. Finding PEAR Packages

    4. Finding Information About a Package

    5. Installing PEAR Packages

    6. Upgrading PEAR Packages

    7. Uninstalling PEAR Packages

    8. Installing PECL Packages

  1. Colophon