Books & Videos

Table of Contents

  1. Chapter 1 Strings

    1. Introduction

    2. Accessing Substrings

    3. Replacing Substrings

    4. Processing a String One Character at a Time

    5. Reversing a String by Word or Character

    6. Expanding and Compressing Tabs

    7. Controlling Case

    8. Interpolating Functions and Expressions Within Strings

    9. Trimming Blanks from a String

    10. Parsing Comma-Separated Data

    11. Parsing Fixed-Width Delimited Data

    12. Taking Strings Apart

    13. Wrapping Text at a Certain Line Length

    14. Storing Binary Data in Strings

  2. Chapter 2 Numbers

    1. Introduction

    2. Checking Whether a String 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. Printing Correct Plurals

    12. Calculating Trigonometric Functions

    13. Doing Trigonometry in Degrees, not Radians

    14. Handling Very Large or Very Small Numbers

    15. Converting Between Bases

    16. Calculating Using Numbers in Bases Other Than Decimal

  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, Year, or the Week Number in a 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 Saving Time

    14. Generating a High-Precision Time

    15. Generating Time Ranges

    16. Using Non-Gregorian Calendars

    17. 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 an Element 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. Shuffling a Deck of Cards

    23. Removing Duplicate Elements from an Array

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

    25. Finding All Element Combinations of an Array

    26. Finding All Permutations of an Array

    27. Program: Printing an Array in 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 as 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. Destroying an Object

    5. Cloning Objects

    6. Assigning Object References

    7. Calling Methods on an Object Returned by Another Method

    8. Accessing Overridden Methods

    9. Using Property Overloading

    10. Using Method Polymorphism

    11. Finding the Methods and Properties of an Object

    12. Adding Properties to a Base Object

    13. Creating a Class Dynamically

    14. Instantiating an Object Dynamically

  8. Chapter 8 Web Basics

    1. Introduction

    2. Setting Cookies

    3. Reading Cookie Values

    4. Deleting Cookies

    5. Redirecting to a Different Location

    6. Using Session Tracking

    7. Storing Sessions in a Database

    8. Detecting Different Browsers

    9. Building a GET Query String

    10. Using HTTP Basic Authentication

    11. Using Cookie Authentication

    12. Flushing Output to the Browser

    13. Buffering Output to the Browser

    14. Compressing Web Output with gzip

    15. Hiding Error Messages from Users

    16. Tuning Error Handling

    17. Using a Custom Error Handler

    18. Logging Errors

    19. Eliminating “headers already sent” Errors

    20. Logging Debugging Information

    21. Reading Environment Variables

    22. Setting Environment Variables

    23. Reading Configuration Variables

    24. Setting Configuration Variables

    25. Communicating Within Apache

    26. Profiling Code

    27. Program: Website Account (De)activator

    28. Program: Abusive User Checker

  9. Chapter 9 Forms

    1. Introduction

    2. Processing Form Input

    3. Validating Form Input

    4. Working with Multipage Forms

    5. Redisplaying Forms with Preserved Information and Error Messages

    6. Guarding Against Multiple Submission of the Same Form

    7. Processing Uploaded Files

    8. Securing PHP’s Form Processing

    9. Escaping Control Characters from User Data

    10. Handling Remote Variables with Periods in Their Names

    11. Using Form Elements with Multiple Options

    12. Creating Dropdown Menus Based on the Current Date

  10. Chapter 10 Database Access

    1. Introduction

    2. Using Text-File Databases

    3. Using DBM Databases

    4. Connecting to a SQL Database

    5. Querying a SQL Database

    6. Retrieving Rows Without a Loop

    7. Modifying Data in a 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. Assigning Unique ID Values Automatically

    13. Building Queries Programmatically

    14. Making Paginated Links for a Series of Records

    15. Caching Queries and Results

    16. Program: Storing a Threaded Message Board

  11. Chapter 11 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 Headers

    6. Fetching an HTTPS URL

    7. Debugging the Raw HTTP Exchange

    8. Marking Up a Web Page

    9. Extracting Links from an HTML File

    10. Converting ASCII to HTML

    11. Converting HTML to ASCII

    12. Removing HTML and PHP Tags

    13. Using Smarty Templates

    14. Parsing a Web Server Log File

    15. Program: Finding Stale Links

    16. Program: Finding Fresh Links

  12. Chapter 12 XML

    1. Introduction

    2. Generating XML Manually

    3. Generating XML with the DOM

    4. Parsing XML with the DOM

    5. Parsing XML with SAX

    6. Transforming XML with XSLT

    7. Sending XML-RPC Requests

    8. Receiving XML-RPC Requests

    9. Sending SOAP Requests

    10. Receiving SOAP Requests

    11. Exchanging Data with WDDX

    12. Reading RSS Feeds

  13. Chapter 13 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. Matching a Valid Email Address

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

    8. Capturing Text Inside HTML Tags

    9. Escaping Special Characters in a Regular Expression

    10. Reading Records with a Pattern Separator

  14. Chapter 14 Encryption and Security

    1. Introduction

    2. Keeping Passwords Out of Your Site Files

    3. Obscuring Data with Encoding

    4. Verifying Data with Hashes

    5. Storing Passwords

    6. Checking Password Strength

    7. Dealing with Lost Passwords

    8. Encrypting and Decrypting Data

    9. Storing Encrypted Data in a File or Database

    10. Sharing Encrypted Data with Another Web Site

    11. Detecting SSL

    12. Encrypting Email with GPG

  15. Chapter 15 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. Serving Images Securely

    10. Program: Generating Bar Charts from Poll Results

  16. Chapter 16 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. Reading or Writing Unicode Characters

  17. Chapter 17 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

  18. Chapter 18 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. Reading a Particular Line in a File

    10. Processing a File Backward by Line or Paragraph

    11. Picking a Random Line from a File

    12. Randomizing All Lines in a File

    13. Processing Variable Length Text Fields

    14. Reading Configuration Files

    15. Reading from or Writing to a Specific Location in a File

    16. Removing the Last Line of a File

    17. Modifying a File in Place Without a Temporary File

    18. Flushing Output to a File

    19. Writing to Standard Output

    20. Writing to Many Filehandles Simultaneously

    21. Escaping Shell Metacharacters

    22. Passing Input to a Program

    23. Reading Standard Output from a Program

    24. Reading Standard Error from a Program

    25. Locking a File

    26. Reading and Writing Compressed Files

    27. Program: Unzip

  19. Chapter 19 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 Recursively

    9. Getting a List of Filenames Matching a Pattern

    10. Processing All Files in a Directory

    11. Making New Directories

    12. Removing a Directory and Its Contents

    13. Program: Web Server Directory Listing

    14. Program: Site Search

  20. Chapter 20 Client-Side PHP

    1. Introduction

    2. Parsing Program Arguments

    3. Parsing Program Arguments with getopt

    4. Reading from the Keyboard

    5. Reading Passwords

    6. Displaying a GUI Widget in a Window

    7. Displaying Multiple GUI Widgets in a Window

    8. Responding to User Actions

    9. Displaying Menus

    10. Program: Command Shell

    11. Program: Displaying Weather Conditions

  21. Chapter 21 PEAR

    1. Introduction

    2. Using the PEAR Package Manager

    3. Finding PEAR Packages

    4. Finding Information About a Package

    5. Installing PEAR Packages

    6. Installing PECL Packages

    7. Upgrading PEAR Packages

    8. Uninstalling PEAR Packages

    9. Documenting Classes with PHPDoc

  1. Colophon