You are previewing PHP Cookbook, 2nd Edition.
O'Reilly logo
PHP Cookbook, 2nd Edition

Book Description

When it comes to creating dynamic web sites, the open source PHP language is red-hot property: used on more than 20 million web sites today, PHP is now more popular than Microsoft's ASP.NET technology. With our Cookbook's unique format, you can learn how to build dynamic web applications that work on any web browser. This revised new edition makes it easy to find specific solutions for programming challenges.

PHP Cookbook has a wealth of solutions for problems that you'll face regularly. With topics that range from beginner questions to advanced web programming techniques, this guide contains practical examples -- or "recipes" -- for anyone who uses this scripting language to generate dynamic web content. Updated for PHP 5, this book provides solutions that explain how to use the new language features in detail, including the vastly improved object-oriented capabilities and the new PDO data access extension. New sections on classes and objects are included, along with new material on processing XML, building web services with PHP, and working with SOAP/REST architectures. With each recipe, the authors include a discussion that explains the logic and concepts underlying the solution.

Table of Contents

  1. PHP Cookbook
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Who This Book Is For
    2. What Is in This Book
    3. Other Resources
      1. Web Sites
      2. Books
    4. Conventions Used in This Book
      1. Programming Conventions
      2. Typesetting Conventions
    5. Comments and Questions
    6. Acknowledgments
      1. David Sklar
      2. Adam Trachtenberg
      3. Clay Loveless
      4. Chris Shiflett
  4. 1. Strings
    1. 1.0. Introduction
    2. 1.1. Accessing Substrings
      1. 1.1.1. Problem
      2. 1.1.2. Solution
      3. 1.1.3. Discussion
      4. 1.1.4. See Also
    3. 1.2. Extracting Substrings
      1. 1.2.1. Problem
      2. 1.2.2. Solution
      3. 1.2.3. Discussion
      4. 1.2.4. See Also
    4. 1.3. Replacing Substrings
      1. 1.3.1. Problem
      2. 1.3.2. Solution
      3. 1.3.3. Discussion
      4. 1.3.4. See Also
    5. 1.4. Processing a String One Byte at a Time
      1. 1.4.1. Problem
      2. 1.4.2. Solution
      3. 1.4.3. Discussion
      4. 1.4.4. See Also
    6. 1.5. Reversing a String by Word or Byte
      1. 1.5.1. Problem
      2. 1.5.2. Solution
      3. 1.5.3. Discussion
      4. 1.5.4. See Also
    7. 1.6. Expanding and Compressing Tabs
      1. 1.6.1. Problem
      2. 1.6.2. Solution
      3. 1.6.3. Discussion
      4. 1.6.4. See Also
    8. 1.7. Controlling Case
      1. 1.7.1. Problem
      2. 1.7.2. Solution
      3. 1.7.3. Discussion
      4. 1.7.4. See Also
    9. 1.8. Interpolating Functions and Expressions Within Strings
      1. 1.8.1. Problem
      2. 1.8.2. Solution
      3. 1.8.3. Discussion
      4. 1.8.4. See Also
    10. 1.9. Trimming Blanks from a String
      1. 1.9.1. Problem
      2. 1.9.2. Solution
      3. 1.9.3. Discussion
      4. 1.9.4. See Also
    11. 1.10. Generating Comma-Separated Data
      1. 1.10.1. Problem
      2. 1.10.2. Solution
      3. 1.10.3. Discussion
      4. 1.10.4. See Also
    12. 1.11. Parsing Comma-Separated Data
      1. 1.11.1. Problem
      2. 1.11.2. Solution
      3. 1.11.3. Discussion
      4. 1.11.4. See Also
    13. 1.12. Generating Fixed-Width Field Data Records
      1. 1.12.1. Problem
      2. 1.12.2. Solution
      3. 1.12.3. Discussion
      4. 1.12.4. See Also
    14. 1.13. Parsing Fixed-Width Field Data Records
      1. 1.13.1. Problem
      2. 1.13.2. Solution
      3. 1.13.3. Discussion
      4. 1.13.4. See Also
    15. 1.14. Taking Strings Apart
      1. 1.14.1. Problem
      2. 1.14.2. Solution
      3. 1.14.3. Discussion
      4. 1.14.4. See Also
    16. 1.15. Wrapping Text at a Certain Line Length
      1. 1.15.1. Problem
      2. 1.15.2. Solution
      3. 1.15.3. Discussion
      4. 1.15.4. See Also
    17. 1.16. Storing Binary Data in Strings
      1. 1.16.1. Problem
      2. 1.16.2. Solution
      3. 1.16.3. Discussion
      4. 1.16.4. See Also
    18. 1.17. Program: Downloadable CSV File
  5. 2. Numbers
    1. 2.0. Introduction
    2. 2.1. Checking Whether a Variable Contains a Valid Number
      1. 2.1.1. Problem
      2. 2.1.2. Solution
      3. 2.1.3. Discussion
      4. 2.1.4. See Also
    3. 2.2. Comparing Floating-Point Numbers
      1. 2.2.1. Problem
      2. 2.2.2. Solution
      3. 2.2.3. Discussion
      4. 2.2.4. See Also
    4. 2.3. Rounding Floating-Point Numbers
      1. 2.3.1. Problem
      2. 2.3.2. Solution
      3. 2.3.3. Discussion
      4. 2.3.4. See Also
    5. 2.4. Operating on a Series of Integers
      1. 2.4.1. Problem
      2. 2.4.2. Solution
      3. 2.4.3. Discussion
      4. 2.4.4. See Also
    6. 2.5. Generating Random Numbers Within a Range
      1. 2.5.1. Problem
      2. 2.5.2. Solution
      3. 2.5.3. Discussion
      4. 2.5.4. See Also
    7. 2.6. Generating Biased Random Numbers
      1. 2.6.1. Problem
      2. 2.6.2. Solution
      3. 2.6.3. Discussion
      4. 2.6.4. See Also
    8. 2.7. Taking Logarithms
      1. 2.7.1. Problem
      2. 2.7.2. Solution
      3. 2.7.3. Discussion
      4. 2.7.4. See Also
    9. 2.8. Calculating Exponents
      1. 2.8.1. Problem
      2. 2.8.2. Solution
      3. 2.8.3. Discussion
      4. 2.8.4. See Also
    10. 2.9. Formatting Numbers
      1. 2.9.1. Problem
      2. 2.9.2. Solution
      3. 2.9.3. Discussion
      4. 2.9.4. See Also
    11. 2.10. Formatting Monetary Values
      1. 2.10.1. Problem
      2. 2.10.2. Solution
      3. 2.10.3. Discussion
      4. 2.10.4. See Also
    12. 2.11. Printing Correct Plurals
      1. 2.11.1. Problem
      2. 2.11.2. Solution
      3. 2.11.3. Discussion
    13. 2.12. Calculating Trigonometric Functions
      1. 2.12.1. Problem
      2. 2.12.2. Solution
      3. 2.12.3. Discussion
      4. 2.12.4. See Also
    14. 2.13. Doing Trigonometry in Degrees, Not Radians
      1. 2.13.1. Problem
      2. 2.13.2. Solution
      3. 2.13.3. Discussion
      4. 2.13.4. See Also
    15. 2.14. Handling Very Large or Very Small Numbers
      1. 2.14.1. Problem
      2. 2.14.2. Solution
      3. 2.14.3. Discussion
      4. 2.14.4. See Also
    16. 2.15. Converting Between Bases
      1. 2.15.1. Problem
      2. 2.15.2. Solution
      3. 2.15.3. Discussion
      4. 2.15.4. See Also
    17. 2.16. Calculating Using Numbers in Bases Other Than Decimal
      1. 2.16.1. Problem
      2. 2.16.2. Solution
      3. 2.16.3. Discussion
      4. 2.16.4. See Also
    18. 2.17. Finding the Distance Between Two Places
      1. 2.17.1. Problem
      2. 2.17.2. Solution
      3. 2.17.3. Discussion
      4. 2.17.4. See Also
  6. 3. Dates and Times
    1. 3.0. Introduction
    2. 3.1. Finding the Current Date and Time
      1. 3.1.1. Problem
      2. 3.1.2. Solution
      3. 3.1.3. Discussion
      4. 3.1.4. See Also
    3. 3.2. Converting Time and Date Parts to an Epoch Timestamp
      1. 3.2.1. Problem
      2. 3.2.2. Solution
      3. 3.2.3. Discussion
      4. 3.2.4. See Also
    4. 3.3. Converting an Epoch Timestamp to Time and Date Parts
      1. 3.3.1. Problem
      2. 3.3.2. Solution
      3. 3.3.3. Discussion
      4. 3.3.4. See Also
    5. 3.4. Printing a Date or Time in a Specified Format
      1. 3.4.1. Problem
      2. 3.4.2. Solution
      3. 3.4.3. Discussion
      4. 3.4.4. See Also
    6. 3.5. Finding the Difference of Two Dates
      1. 3.5.1. Problem
      2. 3.5.2. Solution
      3. 3.5.3. Discussion
      4. 3.5.4. See Also
    7. 3.6. Finding the Difference of Two Dates with Julian Days
      1. 3.6.1. Problem
      2. 3.6.2. Solution
      3. 3.6.3. Discussion
      4. 3.6.4. See Also
    8. 3.7. Finding the Day in a Week, Month, or Year
      1. 3.7.1. Problem
      2. 3.7.2. Solution
      3. 3.7.3. Discussion
      4. 3.7.4. See Also
    9. 3.8. Validating a Date
      1. 3.8.1. Problem
      2. 3.8.2. Solution
      3. 3.8.3. Discussion
      4. 3.8.4. See Also
    10. 3.9. Parsing Dates and Times from Strings
      1. 3.9.1. Problem
      2. 3.9.2. Solution
      3. 3.9.3. Discussion
      4. 3.9.4. See Also
    11. 3.10. Adding to or Subtracting from a Date
      1. 3.10.1. Problem
      2. 3.10.2. Solution
      3. 3.10.3. Discussion
      4. 3.10.4. See Also
    12. 3.11. Calculating Time with Time Zones
      1. 3.11.1. Problem
      2. 3.11.2. Solution
      3. 3.11.3. Discussion
      4. 3.11.4. See Also
    13. 3.12. Accounting for Daylight Savings Time
      1. 3.12.1. Problem
      2. 3.12.2. Solution
      3. 3.12.3. Discussion
      4. 3.12.4. See Also
    14. 3.13. Generating a High-Precision Time
      1. 3.13.1. Problem
      2. 3.13.2. Solution
      3. 3.13.3. Discussion
      4. 3.13.4. See Also
    15. 3.14. Generating Time Ranges
      1. 3.14.1. Problem
      2. 3.14.2. Solution
      3. 3.14.3. Discussion
      4. 3.14.4. See Also
    16. 3.15. Using Non-Gregorian Calendars
      1. 3.15.1. Problem
      2. 3.15.2. Solution
      3. 3.15.3. Discussion
      4. 3.15.4. See Also
    17. 3.16. Using Dates Outside the Range of an Epoch Timestamp
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 3.17. Program: Calendar
  7. 4. Arrays
    1. 4.0. Introduction
    2. 4.1. Specifying an Array Not Beginning at Element 0
      1. 4.1.1. Problem
      2. 4.1.2. Solution
      3. 4.1.3. Discussion
      4. 4.1.4. See Also
    3. 4.2. Storing Multiple Elements Per Key in an Array
      1. 4.2.1. Problem
      2. 4.2.2. Solution
      3. 4.2.3. Discussion
      4. 4.2.4. See Also
    4. 4.3. Initializing an Array to a Range of Integers
      1. 4.3.1. Problem
      2. 4.3.2. Solution
      3. 4.3.3. Discussion
      4. 4.3.4. See Also
    5. 4.4. Iterating Through an Array
      1. 4.4.1. Problem
      2. 4.4.2. Solution
      3. 4.4.3. Discussion
      4. 4.4.4. See Also
    6. 4.5. Deleting Elements from an Array
      1. 4.5.1. Problem
      2. 4.5.2. Solution
      3. 4.5.3. Discussion
      4. 4.5.4. See Also
    7. 4.6. Changing Array Size
      1. 4.6.1. Problem
      2. 4.6.2. Solution
      3. 4.6.3. Discussion
      4. 4.6.4. See Also
    8. 4.7. Appending One Array to Another
      1. 4.7.1. Problem
      2. 4.7.2. Solution
      3. 4.7.3. Discussion
      4. 4.7.4. See Also
    9. 4.8. Turning an Array into a String
      1. 4.8.1. Problem
      2. 4.8.2. Solution
      3. 4.8.3. Discussion
      4. 4.8.4. See Also
    10. 4.9. Printing an Array with Commas
      1. 4.9.1. Problem
      2. 4.9.2. Solution
      3. 4.9.3. Discussion
      4. 4.9.4. See Also
    11. 4.10. Checking if a Key Is in an Array
      1. 4.10.1. Problem
      2. 4.10.2. Solution
      3. 4.10.3. Discussion
      4. 4.10.4. See Also
    12. 4.11. Checking if an Element Is in an Array
      1. 4.11.1. Problem
      2. 4.11.2. Solution
      3. 4.11.3. Discussion
      4. 4.11.4. See Also
    13. 4.12. Finding the Position of a Value in an Array
      1. 4.12.1. Problem
      2. 4.12.2. Solution
      3. 4.12.3. Discussion
      4. 4.12.4. See Also
    14. 4.13. Finding Elements That Pass a Certain Test
      1. 4.13.1. Problem
      2. 4.13.2. Solution
      3. 4.13.3. Discussion
      4. 4.13.4. See Also
    15. 4.14. Finding the Largest or Smallest Valued Element in an Array
      1. 4.14.1. Problem
      2. 4.14.2. Solution
      3. 4.14.3. Discussion
      4. 4.14.4. See Also
    16. 4.15. Reversing an Array
      1. 4.15.1. Problem
      2. 4.15.2. Solution
      3. 4.15.3. Discussion
      4. 4.15.4. See Also
    17. 4.16. Sorting an Array
      1. 4.16.1. Problem
      2. 4.16.2. Solution
      3. 4.16.3. Discussion
      4. 4.16.4. See Also
    18. 4.17. Sorting an Array by a Computable Field
      1. 4.17.1. Problem
      2. 4.17.2. Solution
      3. 4.17.3. Discussion
      4. 4.17.4. See Also
    19. 4.18. Sorting Multiple Arrays
      1. 4.18.1. Problem
      2. 4.18.2. Solution
      3. 4.18.3. Discussion
      4. 4.18.4. See Also
    20. 4.19. Sorting an Array Using a Method Instead of a Function
      1. 4.19.1. Problem
      2. 4.19.2. Solution
      3. 4.19.3. Discussion
      4. 4.19.4. See Also
    21. 4.20. Randomizing an Array
      1. 4.20.1. Problem
      2. 4.20.2. Solution
      3. 4.20.3. Discussion
      4. 4.20.4. See Also
    22. 4.21. Removing Duplicate Elements from an Array
      1. 4.21.1. Problem
      2. 4.21.2. Solution
      3. 4.21.3. Discussion
      4. 4.21.4. See Also
    23. 4.22. Applying a Function to Each Element in an Array
      1. 4.22.1. Problem
      2. 4.22.2. Solution
      3. 4.22.3. Discussion
      4. 4.22.4. See Also
    24. 4.23. Finding the Union, Intersection, or Difference of Two Arrays
      1. 4.23.1. Problem
      2. 4.23.2. Solution
      3. 4.23.3. Discussion
      4. 4.23.4. See Also
    25. 4.24. Making an Object Act like an Array
      1. 4.24.1. Problem
      2. 4.24.2. Solution
      3. 4.24.3. Discussion
      4. 4.24.4. See Also
    26. 4.25. Program: Printing a Horizontally Columned HTML Table
  8. 5. Variables
    1. 5.0. Introduction
    2. 5.1. Avoiding == Versus = Confusion
      1. 5.1.1. Problem
      2. 5.1.2. Solution
      3. 5.1.3. Discussion
      4. 5.1.4. See Also
    3. 5.2. Establishing a Default Value
      1. 5.2.1. Problem
      2. 5.2.2. Solution
      3. 5.2.3. Discussion
      4. 5.2.4. See Also
    4. 5.3. Exchanging Values Without Using Temporary Variables
      1. 5.3.1. Problem
      2. 5.3.2. Solution
      3. 5.3.3. Discussion
      4. 5.3.4. See Also
    5. 5.4. Creating a Dynamic Variable Name
      1. 5.4.1. Problem
      2. 5.4.2. Solution
      3. 5.4.3. Discussion
      4. 5.4.4. See Also
    6. 5.5. Using Static Variables
      1. 5.5.1. Problem
      2. 5.5.2. Solution
      3. 5.5.3. Discussion
      4. 5.5.4. See Also
    7. 5.6. Sharing Variables Between Processes
      1. 5.6.1. Problem
      2. 5.6.2. Solution
      3. 5.6.3. Discussion
      4. 5.6.4. See Also
    8. 5.7. Encapsulating Complex Data Types in a String
      1. 5.7.1. Problem
      2. 5.7.2. Solution
      3. 5.7.3. Discussion
      4. 5.7.4. See Also
    9. 5.8. Dumping Variable Contents as Strings
      1. 5.8.1. Problem
      2. 5.8.2. Solution
      3. 5.8.3. Discussion
      4. 5.8.4. See Also
  9. 6. Functions
    1. 6.0. Introduction
    2. 6.1. Accessing Function Parameters
      1. 6.1.1. Problem
      2. 6.1.2. Solution
      3. 6.1.3. Discussion
      4. 6.1.4. See Also
    3. 6.2. Setting Default Values for Function Parameters
      1. 6.2.1. Problem
      2. 6.2.2. Solution
      3. 6.2.3. Discussion
      4. 6.2.4. See Also
    4. 6.3. Passing Values by Reference
      1. 6.3.1. Problem
      2. 6.3.2. Solution
      3. 6.3.3. Discussion
      4. 6.3.4. See Also
    5. 6.4. Using Named Parameters
      1. 6.4.1. Problem
      2. 6.4.2. Solution
      3. 6.4.3. Discussion
      4. 6.4.4. See Also
    6. 6.5. Creating Functions That Take a Variable Number of Arguments
      1. 6.5.1. Problem
      2. 6.5.2. Solution
      3. 6.5.3. Discussion
      4. 6.5.4. See Also
    7. 6.6. Returning Values by Reference
      1. 6.6.1. Problem
      2. 6.6.2. Solution
      3. 6.6.3. Discussion
      4. 6.6.4. See Also
    8. 6.7. Returning More Than One Value
      1. 6.7.1. Problem
      2. 6.7.2. Solution
      3. 6.7.3. Discussion
      4. 6.7.4. See Also
    9. 6.8. Skipping Selected Return Values
      1. 6.8.1. Problem
      2. 6.8.2. Solution
      3. 6.8.3. Discussion
      4. 6.8.4. See Also
    10. 6.9. Returning Failure
      1. 6.9.1. Problem
      2. 6.9.2. Solution
      3. 6.9.3. Discussion
      4. 6.9.4. See Also
    11. 6.10. Calling Variable Functions
      1. 6.10.1. Problem
      2. 6.10.2. Solution
      3. 6.10.3. Discussion
      4. 6.10.4. See Also
    12. 6.11. Accessing a Global Variable Inside a Function
      1. 6.11.1. Problem
      2. 6.11.2. Solution
      3. 6.11.3. Discussion
      4. 6.11.4. See Also
    13. 6.12. Creating Dynamic Functions
      1. 6.12.1. Problem
      2. 6.12.2. Solution
      3. 6.12.3. Discussion
      4. 6.12.4. See Also
  10. 7. Classes and Objects
    1. 7.0. Introduction
    2. 7.1. Instantiating Objects
      1. 7.1.1. Problem
      2. 7.1.2. Solution
      3. 7.1.3. Discussion
      4. 7.1.4. See Also
    3. 7.2. Defining Object Constructors
      1. 7.2.1. Problem
      2. 7.2.2. Solution
      3. 7.2.3. Discussion
      4. 7.2.4. See Also
    4. 7.3. Defining Object Destructors
      1. 7.3.1. Problem
      2. 7.3.2. Solution
      3. 7.3.3. Discussion
      4. 7.3.4. See Also
    5. 7.4. Implementing Access Control
      1. 7.4.1. Problem
      2. 7.4.2. Solution
      3. 7.4.3. Discussion
    6. 7.5. Preventing Changes to Classes and Methods
      1. 7.5.1. Problem
      2. 7.5.2. Solution
      3. 7.5.3. Discussion
    7. 7.6. Defining Object Stringification
      1. 7.6.1. Problem
      2. 7.6.2. Solution
      3. 7.6.3. Discussion
    8. 7.7. Specifying Interfaces
      1. 7.7.1. Problem
      2. 7.7.2. Solution
      3. 7.7.3. Discussion
      4. 7.7.4. See Also
    9. 7.8. Creating Abstract Base Classes
      1. 7.8.1. Problem
      2. 7.8.2. Solution
      3. 7.8.3. Discussion
    10. 7.9. Assigning Object References
      1. 7.9.1. Problem
      2. 7.9.2. Solution
      3. 7.9.3. Discussion
      4. 7.9.4. See Also
    11. 7.10. Cloning Objects
      1. 7.10.1. Problem
      2. 7.10.2. Solution
      3. 7.10.3. Discussion
      4. 7.10.4. See Also
    12. 7.11. Overriding Property Accesses
      1. 7.11.1. Problem
      2. 7.11.2. Solution
      3. 7.11.3. Discussion
      4. 7.11.4. See Also
    13. 7.12. Calling Methods on an Object Returned by Another Method
      1. 7.12.1. Problem
      2. 7.12.2. Solution
      3. 7.12.3. Discussion
    14. 7.13. Aggregating Objects
      1. 7.13.1. Problem
      2. 7.13.2. Solution
      3. 7.13.3. Discussion
      4. 7.13.4. See Also
    15. 7.14. Accessing Overridden Methods
      1. 7.14.1. Problem
      2. 7.14.2. Solution
      3. 7.14.3. Discussion
      4. 7.14.4. See Also
    16. 7.15. Using Method Polymorphism
      1. 7.15.1. Problem
      2. 7.15.2. Solution
      3. 7.15.3. Discussion
      4. 7.15.4. See Also
    17. 7.16. Defining Class Constants
      1. 7.16.1. Problem
      2. 7.16.2. Solution
      3. 7.16.3. Discussion
      4. 7.16.4. See Also
    18. 7.17. Defining Static Properties and Methods
      1. 7.17.1. Problem
      2. 7.17.2. Solution
      3. 7.17.3. Discussion
      4. 7.17.4. See Also
    19. 7.18. Controlling Object Serialization
      1. 7.18.1. Problem
      2. 7.18.2. Solution
      3. 7.18.3. Discussion
      4. 7.18.4. See Also
    20. 7.19. Introspecting Objects
      1. 7.19.1. Problem
      2. 7.19.2. Solution
      3. 7.19.3. Discussion
      4. 7.19.4. See Also
    21. 7.20. Checking if an Object Is an Instance of a Specific Class
      1. 7.20.1. Problem
      2. 7.20.2. Solution
      3. 7.20.3. Discussion
      4. 7.20.4. See Also
    22. 7.21. Autoloading Class Files upon Object Instantiation
      1. 7.21.1. Problem
      2. 7.21.2. Solution
      3. 7.21.3. Discussion
      4. 7.21.4. See Also
    23. 7.22. Instantiating an Object Dynamically
      1. 7.22.1. Problem
      2. 7.22.2. Solution
      3. 7.22.3. Discussion
      4. 7.22.4. See Also
    24. 7.23. Program: whereis
  11. 8. Web Basics
    1. 8.0. Introduction
    2. 8.1. Setting Cookies
      1. 8.1.1. Problem
      2. 8.1.2. Solution
      3. 8.1.3. Discussion
      4. 8.1.4. See Also
    3. 8.2. Reading Cookie Values
      1. 8.2.1. Problem
      2. 8.2.2. Solution
      3. 8.2.3. Discussion
      4. 8.2.4. See Also
    4. 8.3. Deleting Cookies
      1. 8.3.1. Problem
      2. 8.3.2. Solution
      3. 8.3.3. Discussion
      4. 8.3.4. See Also
    5. 8.4. Redirecting to a Different Location
      1. 8.4.1. Problem
      2. 8.4.2. Solution
      3. 8.4.3. Discussion
      4. 8.4.4. See Also
    6. 8.5. Detecting Different Browsers
      1. 8.5.1. Problem
      2. 8.5.2. Solution
      3. 8.5.3. Discussion
      4. 8.5.4. See Also
    7. 8.6. Building a Query String
      1. 8.6.1. Problem
      2. 8.6.2. Solution
      3. 8.6.3. Discussion
      4. 8.6.4. See Also
    8. 8.7. Reading the Post Request Body
      1. 8.7.1. Problem
      2. 8.7.2. Solution
      3. 8.7.3. Discussion
      4. 8.7.4. See Also
    9. 8.8. Generating HTML Tables with Alternating Row Styles
      1. 8.8.1. Problem
      2. 8.8.2. Solution
      3. 8.8.3. Discussion
      4. 8.8.4. See Also
    10. 8.9. Using HTTP Basic or Digest Authentication
      1. 8.9.1. Problem
      2. 8.9.2. Solution
      3. 8.9.3. Discussion
      4. 8.9.4. See Also
    11. 8.10. Using Cookie Authentication
      1. 8.10.1. Problem
      2. 8.10.2. Solution
      3. 8.10.3. Discussion
      4. 8.10.4. See Also
    12. 8.11. Flushing Output to the Browser
      1. 8.11.1. Problem
      2. 8.11.2. Solution
      3. 8.11.3. Discussion
      4. 8.11.4. See Also
    13. 8.12. Buffering Output to the Browser
      1. 8.12.1. Problem
      2. 8.12.2. Solution
      3. 8.12.3. Discussion
      4. 8.12.4. See Also
    14. 8.13. Compressing Web Output
      1. 8.13.1. Problem
      2. 8.13.2. Solution
      3. 8.13.3. Discussion
      4. 8.13.4. See Also
    15. 8.14. Reading Environment Variables
      1. 8.14.1. Problem
      2. 8.14.2. Solution
      3. 8.14.3. Discussion
      4. 8.14.4. See Also
    16. 8.15. Setting Environment Variables
      1. 8.15.1. Problem
      2. 8.15.2. Solution
      3. 8.15.3. Discussion
      4. 8.15.4. See Also
    17. 8.16. Communicating Within Apache
      1. 8.16.1. Problem
      2. 8.16.2. Solution
      3. 8.16.3. Discussion
      4. 8.16.4. See Also
    18. 8.17. Program: Web Site Account (De)activator
    19. 8.18. Program: Tiny Wiki
  12. 9. Form
    1. 9.0. Introduction
    2. 9.1. Processing Form Input
      1. 9.1.1. Problem
      2. 9.1.2. Solution
      3. 9.1.3. Discussion
      4. 9.1.4. See Also
    3. 9.2. Validating Form Input: Required Fields
      1. 9.2.1. Problem
      2. 9.2.2. Solution
      3. 9.2.3. Discussion
      4. 9.2.4. See Also
    4. 9.3. Validating Form Input: Numbers
      1. 9.3.1. Problem
      2. 9.3.2. Solution
      3. 9.3.3. Discussion
      4. 9.3.4. See Also
    5. 9.4. Validating Form Input: Email Addresses
      1. 9.4.1. Problem
      2. 9.4.2. Solution
      3. 9.4.3. Discussion
      4. 9.4.4. See Also
    6. 9.5. Validating Form Input: Drop-Down Menus
      1. 9.5.1. Problem
      2. 9.5.2. Solution
      3. 9.5.3. Discussion
      4. 9.5.4. See Also
    7. 9.6. Validating Form Input: Radio Buttons
      1. 9.6.1. Problem
      2. 9.6.2. Solution
      3. 9.6.3. Discussion
      4. 9.6.4. See Also
    8. 9.7. Validating Form Input: Checkboxes
      1. 9.7.1. Problem
      2. 9.7.2. Solution
      3. 9.7.3. Discussion
      4. 9.7.4. See Also
    9. 9.8. Validating Form Input: Dates and Times
      1. 9.8.1. Problem
      2. 9.8.2. Solution
      3. 9.8.3. Discussion
      4. 9.8.4. See Also
    10. 9.9. Validating Form Input: Credit Cards
      1. 9.9.1. Problem
      2. 9.9.2. Solution
      3. 9.9.3. Discussion
      4. 9.9.4. See Also
    11. 9.10. Preventing Cross-Site Scripting
      1. 9.10.1. Problem
      2. 9.10.2. Solution
      3. 9.10.3. Discussion
      4. 9.10.4. See Also
    12. 9.11. Working with Multipage Forms
      1. 9.11.1. Problem
      2. 9.11.2. Solution
      3. 9.11.3. Discussion
      4. 9.11.4. See Also
    13. 9.12. Redisplaying Forms with Inline Error Messages
      1. 9.12.1. Problem
      2. 9.12.2. Solution
      3. 9.12.3. Discussion
      4. 9.12.4. See Also
    14. 9.13. Guarding Against Multiple Submission of the Same Form
      1. 9.13.1. Problem
      2. 9.13.2. Solution
      3. 9.13.3. Discussion
      4. 9.13.4. See Also
    15. 9.14. Processing Uploaded Files
      1. 9.14.1. Problem
      2. 9.14.2. Solution
      3. 9.14.3. Discussion
      4. 9.14.4. See Also
    16. 9.15. Preventing Global Variable Injection
      1. 9.15.1. Problem
      2. 9.15.2. Solution
      3. 9.15.3. Discussion
      4. 9.15.4. See Also
    17. 9.16. Handling Remote Variables with Periods in Their Names
      1. 9.16.1. Problem
      2. 9.16.2. Solution
      3. 9.16.3. Discussion
      4. 9.16.4. See Also
    18. 9.17. Using Form Elements with Multiple Options
      1. 9.17.1. Problem
      2. 9.17.2. Solution
      3. 9.17.3. Discussion
      4. 9.17.4. See Also
    19. 9.18. Creating Drop-Down Menus Based on the Current Date
      1. 9.18.1. Problem
      2. 9.18.2. Solution
      3. 9.18.3. Discussion
      4. 9.18.4. See Also
  13. 10. Database Access
    1. 10.0. Introduction
    2. 10.1. Using DBM Databases
      1. 10.1.1. Problem
      2. 10.1.2. Solution
      3. 10.1.3. Discussion
      4. 10.1.4. See Also
    3. 10.2. Using an SQLite Database
      1. 10.2.1. Problem
      2. 10.2.2. Solution
      3. 10.2.3. Discussion
      4. 10.2.4. See Also
    4. 10.3. Connecting to an SQL Database
      1. 10.3.1. Problem
      2. 10.3.2. Solution
      3. 10.3.3. Discussion
      4. 10.3.4. See Also
    5. 10.4. Querying an SQL Database
      1. 10.4.1. Problem
      2. 10.4.2. Solution
      3. 10.4.3. Discussion
      4. 10.4.4. See Also
    6. 10.5. Retrieving Rows Without a Loop
      1. 10.5.1. Problem
      2. 10.5.2. Solution
      3. 10.5.3. Discussion
      4. 10.5.4. See Also
    7. 10.6. Modifying Data in an SQL Database
      1. 10.6.1. Problem
      2. 10.6.2. Solution
      3. 10.6.3. Discussion
      4. 10.6.4. See Also
    8. 10.7. Repeating Queries Efficiently
      1. 10.7.1. Problem
      2. 10.7.2. Solution
      3. 10.7.3. Discussion
      4. 10.7.4. See Also
    9. 10.8. Finding the Number of Rows Returned by a Query
      1. 10.8.1. Problem
      2. 10.8.2. Solution
      3. 10.8.3. Discussion
      4. 10.8.4. See Also
    10. 10.9. Escaping Quotes
      1. 10.9.1. Problem
      2. 10.9.2. Solution
      3. 10.9.3. Discussion
      4. 10.9.4. See Also
    11. 10.10. Logging Debugging Information and Errors
      1. 10.10.1. Problem
      2. 10.10.2. Solution
      3. 10.10.3. Discussion
      4. 10.10.4. See Also
    12. 10.11. Creating Unique Identifiers
      1. 10.11.1. Problem
      2. 10.11.2. Solution
      3. 10.11.3. Discussion
      4. 10.11.4. See Also
    13. 10.12. Building Queries Programmatically
      1. 10.12.1. Problem
      2. 10.12.2. Solution
      3. 10.12.3. Discussion
      4. 10.12.4. See Also
    14. 10.13. Making Paginated Links for a Series of Records
      1. 10.13.1. Problem
      2. 10.13.2. Solution
      3. 10.13.3. Discussion
      4. 10.13.4. See Also
    15. 10.14. Caching Queries and Results
      1. 10.14.1. Problem
      2. 10.14.2. Solution
      3. 10.14.3. Discussion
      4. 10.14.4. See Also
    16. 10.15. Accessing a Database Connection Anywhere in Your Program
      1. 10.15.1. Problem
      2. 10.15.2. Solution
      3. 10.15.3. Discussion
      4. 10.15.4. See Also
    17. 10.16. Program: Storing a Threaded Message Board
  14. 11. Sessions and Data Persistence
    1. 11.0. Introduction
    2. 11.1. Using Session Tracking
      1. 11.1.1. Problem
      2. 11.1.2. Solution
      3. 11.1.3. Discussion
      4. 11.1.4. See Also
    3. 11.2. Preventing Session Hijacking
      1. 11.2.1. Problem
      2. 11.2.2. Solution
      3. 11.2.3. Discussion
      4. 11.2.4. See Also
    4. 11.3. Preventing Session Fixation
      1. 11.3.1. Problem
      2. 11.3.2. Solution
      3. 11.3.3. Discussion
      4. 11.3.4. See Also
    5. 11.4. Storing Sessions in a Database
      1. 11.4.1. Problem
      2. 11.4.2. Solution
      3. 11.4.3. Discussion
      4. 11.4.4. See Also
    6. 11.5. Storing Sessions in Shared Memory
      1. 11.5.1. Problem
      2. 11.5.2. Solution
      3. 11.5.3. Discussion
      4. 11.5.4. See Also
    7. 11.6. Storing Arbitrary Data in Shared Memory
      1. 11.6.1. Problem
      2. 11.6.2. Solution
      3. 11.6.3. Discussion
      4. 11.6.4. See Also
    8. 11.7. Caching Calculated Results in Summary Tables
      1. 11.7.1. Problem
      2. 11.7.2. Solution
      3. 11.7.3. Discussion
      4. 11.7.4. See Also
  15. 12. XML
    1. 12.0. Introduction
    2. 12.1. Generating XML as a String
      1. 12.1.1. Problem
      2. 12.1.2. Solution
      3. 12.1.3. Discussion
      4. 12.1.4. See Also
    3. 12.2. Generating XML with the DOM
      1. 12.2.1. Problem
      2. 12.2.2. Solution
      3. 12.2.3. Discussion
      4. 12.2.4. See Also
    4. 12.3. Parsing Basic XML Documents
      1. 12.3.1. Problem
      2. 12.3.2. Solution
      3. 12.3.3. Discussion
      4. 12.3.4. See Also
    5. 12.4. Parsing Complex XML Documents
      1. 12.4.1. Problem
      2. 12.4.2. Solution
      3. 12.4.3. Discussion
      4. 12.4.4. See Also
    6. 12.5. Parsing Large XML Documents
      1. 12.5.1. Problem
      2. 12.5.2. Solution
      3. 12.5.3. Discussion
      4. 12.5.4. See Also
    7. 12.6. Extracting Information Using XPath
      1. 12.6.1. Problem
      2. 12.6.2. Solution
      3. 12.6.3. Discussion
      4. 12.6.4. See Also
    8. 12.7. Transforming XML with XSLT
      1. 12.7.1. Problem
      2. 12.7.2. Solution
      3. 12.7.3. Discussion
      4. 12.7.4. See Also
    9. 12.8. Setting XSLT Parameters from PHP
      1. 12.8.1. Problem
      2. 12.8.2. Solution
      3. 12.8.3. Discussion
      4. 12.8.4. See Also
    10. 12.9. Calling PHP Functions from XSLT Stylesheets
      1. 12.9.1. Problem
      2. 12.9.2. Solution
      3. 12.9.3. Discussion
      4. 12.9.4. See Also
    11. 12.10. Validating XML Documents
      1. 12.10.1. Problem
      2. 12.10.2. Solution
      3. 12.10.3. Discussion
      4. 12.10.4. See Also
    12. 12.11. Handling Content Encoding
      1. 12.11.1. Problem
      2. 12.11.2. Solution
      3. 12.11.3. Discussion
      4. 12.11.4. See Also
    13. 12.12. Reading RSS and Atom Feeds
      1. 12.12.1. Problem
      2. 12.12.2. Solution
      3. 12.12.3. Discussion
      4. 12.12.4. See Also
    14. 12.13. Writing RSS Feeds
      1. 12.13.1. Problem
      2. 12.13.2. Solution
      3. 12.13.3. Discussion
    15. 12.14. Writing Atom Feeds
      1. 12.14.1. Problem
      2. 12.14.2. Solution
      3. 12.14.3. Discussion
      4. 12.14.4. See Also
  16. 13. Web Automation
    1. 13.0. Introduction
    2. 13.1. Fetching a URL with the Get Method
      1. 13.1.1. Problem
      2. 13.1.2. Solution
      3. 13.1.3. Discussion
      4. 13.1.4. See Also
    3. 13.2. Fetching a URL with the Post Method
      1. 13.2.1. Problem
      2. 13.2.2. Solution
      3. 13.2.3. Discussion
      4. 13.2.4. See Also
    4. 13.3. Fetching a URL with Cookies
      1. 13.3.1. Problem
      2. 13.3.2. Solution
      3. 13.3.3. Discussion
      4. 13.3.4. See Also
    5. 13.4. Fetching a URL with Arbitrary Headers
      1. 13.4.1. Problem
      2. 13.4.2. Solution
      3. 13.4.3. Discussion
      4. 13.4.4. See Also
    6. 13.5. Fetching a URL with an Arbitrary Method
      1. 13.5.1. Problem
      2. 13.5.2. Solution
      3. 13.5.3. Discussion
      4. 13.5.4. See Also
    7. 13.6. Fetching a URL with a Timeout
      1. 13.6.1. Problem
      2. 13.6.2. Solution
      3. 13.6.3. Discussion
      4. 13.6.4. See Also
    8. 13.7. Fetching an HTTPS URL
      1. 13.7.1. Problem
      2. 13.7.2. Solution
      3. 13.7.3. Discussion
      4. 13.7.4. See Also
    9. 13.8. Debugging the Raw HTTP Exchange
      1. 13.8.1. Problem
      2. 13.8.2. Solution
      3. 13.8.3. Discussion
      4. 13.8.4. See Also
    10. 13.9. Marking Up a Web Page
      1. 13.9.1. Problem
      2. 13.9.2. Solution
      3. 13.9.3. Discussion
      4. 13.9.4. See Also
    11. 13.10. Cleaning Up Broken or Nonstandard HTML
      1. 13.10.1. Problem
      2. 13.10.2. Solution
      3. 13.10.3. Discussion
      4. 13.10.4. See Also
    12. 13.11. Extracting Links from an HTML File
      1. 13.11.1. Problem
      2. 13.11.2. Solution
      3. 13.11.3. Discussion
      4. 13.11.4. See Also
    13. 13.12. Converting Plain Text to HTML
      1. 13.12.1. Problem
      2. 13.12.2. Solution
      3. 13.12.3. Discussion
      4. 13.12.4. See Also
    14. 13.13. Converting HTML to Plain Text
      1. 13.13.1. Problem
      2. 13.13.2. Solution
      3. 13.13.3. Discussion
      4. 13.13.4. See Also
    15. 13.14. Removing HTML and PHP Tags
      1. 13.14.1. Problem
      2. 13.14.2. Solution
      3. 13.14.3. Discussion
      4. 13.14.4. See Also
    16. 13.15. Responding to an Ajax Request
      1. 13.15.1. Problem
      2. 13.15.2. Solution
      3. 13.15.3. Discussion
      4. 13.15.4. See Also
    17. 13.16. Integrating with JavaScript
      1. 13.16.1. Problem
      2. 13.16.2. Solution
      3. 13.16.3. Discussion
      4. 13.16.4. See Also
    18. 13.17. Program: Finding Stale Links
    19. 13.18. Program: Finding Fresh Links
  17. 14. Consuming Web Services
    1. 14.0. Introduction
    2. 14.1. Calling a REST Method
      1. 14.1.1. Problem
      2. 14.1.2. Solution
      3. 14.1.3. Discussion
      4. 14.1.4. See Also
    3. 14.2. Calling a SOAP Method with WSDL
      1. 14.2.1. Problem
      2. 14.2.2. Solution
      3. 14.2.3. Discussion
      4. 14.2.4. See Also
    4. 14.3. Calling a SOAP Method Without WSDL
      1. 14.3.1. Problem
      2. 14.3.2. Solution
      3. 14.3.3. Discussion
      4. 14.3.4. See Also
    5. 14.4. Debugging SOAP Requests
      1. 14.4.1. Problem
      2. 14.4.2. Solution
      3. 14.4.3. Discussion
    6. 14.5. Using Complex SOAP Types
      1. 14.5.1. Problem
      2. 14.5.2. Solution
      3. 14.5.3. Discussion
      4. 14.5.4. See Also
    7. 14.6. Setting SOAP Types
      1. 14.6.1. Problem
      2. 14.6.2. Solution
      3. 14.6.3. Discussion
      4. 14.6.4. See Also
    8. 14.7. Using SOAP Headers
      1. 14.7.1. Problem
      2. 14.7.2. Solution
      3. 14.7.3. Discussion
      4. 14.7.4. See Also
    9. 14.8. Using Authentication with SOAP
      1. 14.8.1. Problem
      2. 14.8.2. Solution
      3. 14.8.3. Discussion
      4. 14.8.4. See Also
    10. 14.9. Redefining an Endpoint
      1. 14.9.1. Problem
      2. 14.9.2. Solution
      3. 14.9.3. Discussion
    11. 14.10. Catching SOAP Faults
      1. 14.10.1. Problem
      2. 14.10.2. Solution
      3. 14.10.3. Discussion
      4. 14.10.4. See Also
    12. 14.11. Mapping XML Schema Data Types to PHP Classes
      1. 14.11.1. Problem
      2. 14.11.2. Solution
      3. 14.11.3. Discussion
    13. 14.12. Calling an XML-RPC Method
      1. 14.12.1. Problem
      2. 14.12.2. Solution
      3. 14.12.3. Discussion
      4. 14.12.4. See Also
    14. 14.13. Using Authentication with XML-RPC
      1. 14.13.1. Problem
      2. 14.13.2. Solution
      3. 14.13.3. Discussion
  18. 15. Building Web Services
    1. 15.0. Introduction
    2. 15.1. Serving a REST Method
      1. 15.1.1. Problem
      2. 15.1.2. Solution
      3. 15.1.3. Discussion
      4. 15.1.4. See Also
    3. 15.2. Serving a SOAP Method
      1. 15.2.1. Problem
      2. 15.2.2. Solution
      3. 15.2.3. Discussion
      4. 15.2.4. See Also
    4. 15.3. Accepting Arguments in a SOAP Method
      1. 15.3.1. Problem
      2. 15.3.2. Solution
      3. 15.3.3. Discussion
      4. 15.3.4. See Also
    5. 15.4. Generating WSDL Automatically
      1. 15.4.1. Problem
      2. 15.4.2. Solution
      3. 15.4.3. Discussion
      4. 15.4.4. See Also
    6. 15.5. Throwing SOAP Faults
      1. 15.5.1. Problem
      2. 15.5.2. Solution
      3. 15.5.3. Discussion
      4. 15.5.4. See Also
    7. 15.6. Processing a SOAP Header
      1. 15.6.1. Problem
      2. 15.6.2. Solution
      3. 15.6.3. Discussion
      4. 15.6.4. See Also
    8. 15.7. Generating a SOAP Header
      1. 15.7.1. Problem
      2. 15.7.2. Solution
      3. 15.7.3. Discussion
      4. 15.7.4. See Also
    9. 15.8. Using Authentication with SOAP
      1. 15.8.1. Problem
      2. 15.8.2. Solution
      3. 15.8.3. Discussion
      4. 15.8.4. See Also
    10. 15.9. Serving an XML-RPC Method
      1. 15.9.1. Problem
      2. 15.9.2. Solution
      3. 15.9.3. Discussion
      4. 15.9.4. See Also
  19. 16. Internet Services
    1. 16.0. Introduction
    2. 16.1. Sending Mail
      1. 16.1.1. Problem
      2. 16.1.2. Solution
      3. 16.1.3. Discussion
      4. 16.1.4. See Also
    3. 16.2. Sending MIME Mail
      1. 16.2.1. Problem
      2. 16.2.2. Solution
      3. 16.2.3. Discussion
      4. 16.2.4. See Also
    4. 16.3. Reading Mail with IMAP or POP3
      1. 16.3.1. Problem
      2. 16.3.2. Solution
      3. 16.3.3. Discussion
      4. 16.3.4. See Also
    5. 16.4. Posting Messages to Usenet Newsgroups
      1. 16.4.1. Problem
      2. 16.4.2. Solution
      3. 16.4.3. Discussion
      4. 16.4.4. See Also
    6. 16.5. Reading Usenet News Messages
      1. 16.5.1. Problem
      2. 16.5.2. Solution
      3. 16.5.3. Discussion
      4. 16.5.4. See Also
    7. 16.6. Getting and Putting Files with FTP
      1. 16.6.1. Problem
      2. 16.6.2. Solution
      3. 16.6.3. Discussion
      4. 16.6.4. See Also
    8. 16.7. Looking Up Addresses with LDAP
      1. 16.7.1. Problem
      2. 16.7.2. Solution
      3. 16.7.3. Discussion
      4. 16.7.4. See Also
    9. 16.8. Using LDAP for User Authentication
      1. 16.8.1. Problem
      2. 16.8.2. Solution
      3. 16.8.3. Discussion
      4. 16.8.4. See Also
    10. 16.9. Performing DNS Lookups
      1. 16.9.1. Problem
      2. 16.9.2. Solution
      3. 16.9.3. Discussion
      4. 16.9.4. See Also
    11. 16.10. Checking if a Host Is Alive
      1. 16.10.1. Problem
      2. 16.10.2. Solution
      3. 16.10.3. Discussion
      4. 16.10.4. See Also
    12. 16.11. Getting Information About a Domain Name
      1. 16.11.1. Problem
      2. 16.11.2. Solution
      3. 16.11.3. Discussion
      4. 16.11.4. See Also
  20. 17. Graphics
    1. 17.0. Introduction
    2. 17.1. Drawing Lines, Rectangles, and Polygons
      1. 17.1.2. Problem
      2. 17.1.3. Solution
      3. 17.1.4. Discussion
      4. 17.1.5. See Also
    3. 17.2. Drawing Arcs, Ellipses, and Circles
      1. 17.2.2. Problem
      2. 17.2.3. Solution
      3. 17.2.4. Discussion
      4. 17.2.5. See Also
    4. 17.3. Drawing with Patterned Lines
      1. 17.3.2. Problem
      2. 17.3.3. Solution
      3. 17.3.4. Discussion
      4. 17.3.5. See Also
    5. 17.4. Drawing Text
      1. 17.4.2. Problem
      2. 17.4.3. Solution
      3. 17.4.4. Discussion
      4. 17.4.5. See Also
    6. 17.5. Drawing Centered Text
      1. 17.5.2. Problem
      2. 17.5.3. Solution
      3. 17.5.4. Discussion
      4. 17.5.5. See Also
    7. 17.6. Building Dynamic Images
      1. 17.6.2. Problem
      2. 17.6.3. Solution
      3. 17.6.4. Discussion
      4. 17.6.5. See Also
    8. 17.7. Getting and Setting a Transparent Color
      1. 17.7.2. Problem
      2. 17.7.3. Solution
      3. 17.7.4. Discussion
      4. 17.7.5. See Also
    9. 17.8. Reading EXIF Data
      1. 17.8.2. Problem
      2. 17.8.3. Solution
      3. 17.8.4. Discussion
      4. 17.8.5. See Also
    10. 17.9. Serving Images Securely
      1. 17.9.2. Problem
      2. 17.9.3. Solution
      3. 17.9.4. Discussion
      4. 17.9.5. See Also
    11. 17.10. Program: Generating Bar Charts from Poll Results
  21. 18. Security and Encryption
    1. 18.0. Introduction
    2. 18.1. Preventing Session Fixation
      1. 18.1.1. Problem
      2. 18.1.2. Solution
      3. 18.1.3. Discussion
      4. See Also
    3. 18.2. Protecting Against Form Spoofing
      1. 18.2.1. Problem
      2. 18.2.2. Solution
      3. 18.2.3. Discussion
    4. 18.3. Ensuring Input Is Filtered
      1. 18.3.1. Problem
      2. 18.3.2. Solution
      3. 18.3.3. Discussion
      4. See Also
    5. 18.4. Avoiding Cross-Site Scripting
      1. 18.4.1. Problem
      2. 18.4.2. Solution
      3. 18.4.3. Discussion
      4. See Also
    6. 18.5. Eliminating SQL Injection
      1. 18.5.1. Problem
      2. 18.5.2. Solution
      3. 18.5.3. Discussion
      4. 18.5.4. See Also
    7. 18.6. Keeping Passwords Out of Your Site Files
      1. 18.6.1. Problem
      2. 18.6.2. Solution
      3. 18.6.3. Discussion
      4. 18.6.4. See Also
    8. 18.7. Storing Passwords
      1. 18.7.1. Problem
      2. 18.7.2. Solution
      3. 18.7.3. Discussion
      4. 18.7.4. See Also
    9. 18.8. Dealing with Lost Passwords
      1. 18.8.1. Problem
      2. 18.8.2. Solution
      3. 18.8.3. Discussion
      4. 18.8.4. See Also
    10. 18.9. Verifying Data with Hashes
      1. 18.9.1. Problem
      2. 18.9.2. Solution
      3. 18.9.3. Discussion
      4. 18.9.4. See Also
    11. 18.10. Encrypting and Decrypting Data
      1. 18.10.1. Problem
      2. 18.10.2. Solution
      3. 18.10.3. Discussion
      4. 18.10.4. See Also
    12. 18.11. Storing Encrypted Data in a File or Database
      1. 18.11.1. Problem
      2. 18.11.2. Solution
      3. 18.11.3. Discussion
      4. 18.11.4. See Also
    13. 18.12. Sharing Encrypted Data with Another Web Site
      1. 18.12.1. Problem
      2. 18.12.2. Solution
      3. 18.12.3. Discussion
      4. 18.12.4. See Also
    14. 18.13. Detecting SSL
      1. 18.13.1. Problem
      2. 18.13.2. Solution
      3. 18.13.3. Discussion
      4. 18.13.4. See Also
    15. 18.14. Encrypting Email with GPG
      1. 18.14.1. Problem
      2. 18.14.2. Solution
      3. 18.14.3. Discussion
      4. 18.14.4. See Also
  22. 19. Internationalization and Localization
    1. 19.0. Introduction
    2. 19.1. Listing Available Locales
      1. 19.1.1. Problem
      2. 19.1.2. Solution
      3. 19.1.3. Discussion
      4. 19.1.4. See Also
    3. 19.2. Using a Particular Locale
      1. 19.2.1. Problem
      2. 19.2.2. Solution
      3. 19.2.3. Discussion
      4. 19.2.4. See Also
    4. 19.3. Setting the Default Locale
      1. 19.3.1. Problem
      2. 19.3.2. Solution
      3. 19.3.3. Discussion
      4. 19.3.4. See Also
    5. 19.4. Localizing Text Messages
      1. 19.4.1. Problem
      2. 19.4.2. Solution
      3. 19.4.3. Discussion
      4. 19.4.4. See Also
    6. 19.5. Localizing Dates and Times
      1. 19.5.1. Problem
      2. 19.5.2. Solution
      3. 19.5.3. Discussion
      4. 19.5.4. See Also
    7. 19.6. Localizing Currency Values
      1. 19.6.1. Problem
      2. 19.6.2. Solution
      3. 19.6.3. Discussion
      4. 19.6.4. See Also
    8. 19.7. Localizing Images
      1. 19.7.1. Problem
      2. 19.7.2. Solution
      3. 19.7.3. Discussion
      4. 19.7.4. See Also
    9. 19.8. Localizing Included Files
      1. 19.8.1. Problem
      2. 19.8.2. Solution
      3. 19.8.3. Discussion
      4. 19.8.4. See Also
    10. 19.9. Managing Localization Resources
      1. 19.9.1. Problem
      2. 19.9.2. Solution
      3. 19.9.3. Discussion
      4. 19.9.4. See Also
    11. 19.10. Using gettext
      1. 19.10.1. Problem
      2. 19.10.2. Solution
      3. 19.10.3. Discussion
      4. 19.10.4. See Also
    12. 19.11. Setting the Character Encoding of Outgoing Data
      1. 19.11.1. Problem
      2. 19.11.2. Solution
      3. 19.11.3. Discussion
      4. 19.11.4. See Also
    13. 19.12. Setting the Character Encoding of Incoming Data
      1. 19.12.1. Problem
      2. 19.12.2. Solution
      3. 19.12.3. Discussion
      4. 19.12.4. See Also
    14. 19.13. Manipulating UTF-8 Text
      1. 19.13.1. Problem
      2. 19.13.2. Solution
      3. 19.13.3. Discussion
      4. 19.13.4. See Also
  23. 20. Error Handling, Debugging, andTesting
    1. 20.0. Introduction
    2. 20.1. Finding and Fixing Parse Errors
      1. 20.1.1. Problem
      2. 20.1.2. Solution
      3. 20.1.3. Discussion
      4. 20.1.4. See Also
    3. 20.2. Creating Your Own Exception Classes
      1. 20.2.1. Problem
      2. 20.2.2. Solution
      3. 20.2.3. Discussion
      4. 20.2.4. See Also
    4. 20.3. Printing a Stack Trace
      1. 20.3.1. Problem
      2. 20.3.2. Solution
      3. 20.3.3. Discussion
      4. 20.3.4. See Also
    5. 20.4. Reading Configuration Variables
      1. 20.4.1. Problem
      2. 20.4.2. Solution
      3. 20.4.3. Discussion
      4. 20.4.4. See Also
    6. 20.5. Setting Configuration Variables
      1. 20.5.1. Problem
      2. 20.5.2. Solution
      3. 20.5.3. Discussion
      4. 20.5.4. See Also
    7. 20.6. Hiding Error Messages from Users
      1. 20.6.1. Problem
      2. 20.6.2. Solution
      3. 20.6.3. Discussion
      4. 20.6.4. See Also
    8. 20.7. Tuning Error Handling
      1. 20.7.1. Problem
      2. 20.7.2. Solution
      3. 20.7.3. Discussion
      4. 20.7.4. See Also
    9. 20.8. Using a Custom Error Handler
      1. 20.8.1. Problem
      2. 20.8.2. Solution
      3. 20.8.3. Discussion
      4. 20.8.4. See Also
    10. 20.9. Logging Errors
      1. 20.9.1. Problem
      2. 20.9.2. Solution
      3. 20.9.3. Discussion
      4. 20.9.4. See Also
    11. 20.10. Eliminating “headers already sent” Errors
      1. 20.10.1. Problem
      2. 20.10.2. Solution
      3. 20.10.3. Discussion
      4. 20.10.4. See Also
    12. 20.11. Logging Debugging Information
      1. 20.11.1. Problem
      2. 20.11.2. Solution
      3. 20.11.3. Discussion
      4. 20.11.4. See Also
    13. 20.12. Using a Debugger Extension
      1. 20.12.1. Problem
      2. 20.12.2. Solution
      3. 20.12.3. Discussion
      4. 20.12.4. See Also
    14. 20.13. Writing a Unit Test
      1. 20.13.1. Problem
      2. 20.13.2. Solution
      3. 20.13.3. Discussion
      4. 20.13.4. See Also
    15. 20.14. Writing a Unit Test Suite
      1. 20.14.1. Problem
      2. 20.14.2. Solution
      3. 20.14.3. Discussion
      4. 20.14.4. See Also
    16. 20.15. Applying a Unit Test to a Web Page
      1. 20.15.1. Problem
      2. 20.15.2. Solution
      3. 20.15.3. Discussion
      4. 20.15.4. See Also
    17. 20.16. Setting Up a Test Environment
      1. 20.16.1. Problem
      2. 20.16.2. Solution
      3. 20.16.3. Discussion
      4. 20.16.4. See Also
  24. 21. Performance Tuning and Load Testing
    1. 21.0. Introduction
    2. 21.1. Timing Function Execution
      1. 21.1.1. Problem
      2. 21.1.2. Solution
      3. 21.1.3. Discussion
      4. 21.1.4. See Also
    3. 21.2. Timing Program Execution
      1. 21.2.1. Problem
      2. 21.2.2. Solution
      3. 21.2.3. Discussion
      4. 21.2.4. See Also
    4. 21.3. Profiling with a Debugger Extension
      1. 21.3.1. Problem
      2. 21.3.2. Solution
      3. 21.3.3. Discussion
      4. 21.3.4. See Also
    5. 21.4. Stress Testing Your Web Site
      1. 21.4.1. Problem
      2. 21.4.2. Solution
      3. 21.4.3. Discussion
      4. 21.4.4. See Also
    6. 21.5. Avoiding Regular Expressions
      1. 21.5.1. Problem
      2. 21.5.2. Solution
      3. 21.5.3. Discussion
      4. 21.5.4. See Also
    7. 21.6. Using an Accelerator
      1. 21.6.1. Problem
      2. 21.6.2. Solution
      3. 21.6.3. Discussion
      4. 21.6.4. See Also
  25. 22. Regular Expressions
    1. 22.0. Introduction
    2. 22.1. Switching from ereg to preg
      1. 22.1.1. Problem
      2. 22.1.2. Solution
      3. 22.1.3. Discussion
      4. 22.1.4. See Also
    3. 22.2. Matching Words
      1. 22.2.1. Problem
      2. 22.2.2. Solution
      3. 22.2.3. Discussion
      4. 22.2.4. See Also
    4. 22.3. Finding the nth Occurrence of a Match
      1. 22.3.1. Problem
      2. 22.3.2. Solution
      3. 22.3.3. Discussion
      4. 22.3.4. See Also
    5. 22.4. Choosing Greedy or Nongreedy Matches
      1. 22.4.1. Problem
      2. 22.4.2. Solution
      3. 22.4.3. Discussion
      4. 22.4.4. See Also
    6. 22.5. Finding All Lines in a File That Match a Pattern
      1. 22.5.1. Problem
      2. 22.5.2. Solution
      3. 22.5.3. Discussion
      4. 22.5.4. See Also
    7. 22.6. Capturing Text Inside HTML Tags
      1. 22.6.1. Problem
      2. 22.6.2. Solution
      3. 22.6.3. Discussion
      4. 22.6.4. See Also
    8. 22.7. Preventing Parentheses from Capturing Text
      1. 22.7.1. Problem
      2. 22.7.2. Solution
      3. 22.7.3. Discussion
      4. 22.7.4. See Also
    9. 22.8. Escaping Special Characters in a Regular Expression
      1. 22.8.1. Problem
      2. 22.8.2. Solution
      3. 22.8.3. Discussion
      4. 22.8.4. See Also
    10. 22.9. Reading Records with a Pattern Separator
      1. 22.9.1. Problem
      2. 22.9.2. Solution
      3. 22.9.3. Discussion
      4. 22.9.4. See Also
    11. 22.10. Using a PHP Function in a Regular Expression
      1. 22.10.1. Problem
      2. 22.10.2. Solution
      3. 22.10.3. Discussion
      4. 22.10.4. See Also
  26. 23. Files
    1. 23.0. Introduction
    2. 23.1. Creating or Opening a Local File
      1. 23.1.1. Problem
      2. 23.1.2. Solution
      3. 23.1.3. Discussion
      4. 23.1.4. See Also
    3. 23.2. Creating a Temporary File
      1. 23.2.1. Problem
      2. 23.2.2. Solution
      3. 23.2.3. Discussion
      4. 23.2.4. See Also
    4. 23.3. Opening a Remote File
      1. 23.3.1. Problem
      2. 23.3.2. Solution
      3. 23.3.3. Discussion
      4. 23.3.4. See Also
    5. 23.4. Reading from Standard Input
      1. 23.4.1. Problem
      2. 23.4.2. Solution
      3. 23.4.3. Discussion
      4. 23.4.4. See Also
    6. 23.5. Reading a File into a String
      1. 23.5.1. Problem
      2. 23.5.2. Solution
      3. 23.5.3. Discussion
      4. 23.5.4. See Also
    7. 23.6. Counting Lines, Paragraphs, or Records in a File
      1. 23.6.1. Problem
      2. 23.6.2. Solution
      3. 23.6.3. Discussion
      4. 23.6.4. See Also
    8. 23.7. Processing Every Word in a File
      1. 23.7.1. Problem
      2. 23.7.2. Solution
      3. 23.7.3. Discussion
      4. 23.7.4. See Also
    9. 23.8. Picking a Random Line from a File
      1. 23.8.1. Problem
      2. 23.8.2. Solution
      3. 23.8.3. Discussion
      4. 23.8.4. See Also
    10. 23.9. Randomizing All Lines in a File
      1. 23.9.1. Problem
      2. 23.9.2. Solution
      3. 23.9.3. Discussion
      4. 23.9.4. See Also
    11. 23.10. Processing Variable-Length Text Fields
      1. 23.10.1. Problem
      2. 23.10.2. Solution
      3. 23.10.3. Discussion
      4. 23.10.4. See Also
    12. 23.11. Reading Configuration Files
      1. 23.11.1. Problem
      2. 23.11.2. Solution
      3. 23.11.3. Discussion
      4. 23.11.4. See Also
    13. 23.12. Modifying a File in Place Without a Temporary File
      1. 23.12.1. Problem
      2. 23.12.2. Solution
      3. 23.12.3. Discussion
      4. 23.12.4. See Also
    14. 23.13. Flushing Output to a File
      1. 23.13.1. Problem
      2. 23.13.2. Solution
      3. 23.13.3. Discussion
      4. 23.13.4. See Also
    15. 23.14. Writing to Standard Output
      1. 23.14.1. Problem
      2. 23.14.2. Solution
      3. 23.14.3. Discussion
      4. 23.14.4. See Also
    16. 23.15. Writing to Many Filehandles Simultaneously
      1. 23.15.1. Problem
      2. 23.15.2. Solution
      3. 23.15.3. Discussion
      4. 23.15.4. See Also
    17. 23.16. Escaping Shell Metacharacters
      1. 23.16.1. Problem
      2. 23.16.2. Solution
      3. 23.16.3. Discussion
      4. 23.16.4. See Also
    18. 23.17. Passing Input to a Program
      1. 23.17.1. Problem
      2. 23.17.2. Solution
      3. 23.17.3. Discussion
      4. 23.17.4. See Also
    19. 23.18. Reading Standard Output from a Program
      1. 23.18.1. Problem
      2. 23.18.2. Solution
      3. 23.18.3. Discussion
      4. 23.18.4. See Also
    20. 23.19. Reading Standard Error from a Program
      1. 23.19.1. Problem
      2. 23.19.2. Solution
      3. 23.19.3. Discussion
      4. 23.19.4. See Also
    21. 23.20. Locking a File
      1. 23.20.1. Problem
      2. 23.20.2. Solution
      3. 23.20.3. Discussion
      4. 23.20.4. See Also
    22. 23.21. Reading and Writing Custom File Types
      1. 23.21.1. Problem
      2. 23.21.2. Solution
      3. 23.21.3. Discussion
      4. 23.21.4. See Also
    23. 23.22. Reading and Writing Compressed Files
      1. 23.22.1. Problem
      2. 23.22.2. Solution
      3. 23.22.3. Discussion
      4. 23.22.4. See Also
  27. 24. Directories
    1. 24.0. Introduction
    2. 24.1. Getting and Setting File Timestamps
      1. 24.1.1. Problem
      2. 24.1.2. Solution
      3. 24.1.3. Discussion
      4. 24.1.4. See Also
    3. 24.2. Getting File Information
      1. 24.2.1. Problem
      2. 24.2.2. Solution
      3. 24.2.3. Discussion
      4. 24.2.4. See Also
    4. 24.3. Changing File Permissions or Ownership
      1. 24.3.1. Problem
      2. 24.3.2. Solution
      3. 24.3.3. Discussion
      4. 24.3.4. See Also
    5. 24.4. Splitting a Filename into Its Component Parts
      1. 24.4.1. Problem
      2. 24.4.2. Solution
      3. 24.4.3. Discussion
      4. 24.4.4. See Also
    6. 24.5. Deleting a File
      1. 24.5.1. Problem
      2. 24.5.2. Solution
      3. 24.5.3. Discussion
      4. 24.5.4. See Also
    7. 24.6. Copying or Moving a File
      1. 24.6.1. Problem
      2. 24.6.2. Solution
      3. 24.6.3. Discussion
      4. 24.6.4. See Also
    8. 24.7. Processing All Files in a Directory
      1. 24.7.1. Problem
      2. 24.7.2. Solution
      3. 24.7.3. Discussion
      4. 24.7.4. See Also
    9. 24.8. Getting a List of Filenames Matching a Pattern
      1. 24.8.1. Problem
      2. 24.8.2. Solution
      3. 24.8.3. Discussion
      4. 24.8.4. See Also
    10. 24.9. Processing All Files in a Directory Recursively
      1. 24.9.1. Problem
      2. 24.9.2. Solution
      3. 24.9.3. Discussion
      4. 24.9.4. See Also
    11. 24.10. Making New Directories
      1. 24.10.1. Problem
      2. 24.10.2. Solution
      3. 24.10.3. Discussion
      4. 24.10.4. See Also
    12. 24.11. Removing a Directory and Its Contents
      1. 24.11.1. Problem
      2. 24.11.2. Solution
      3. 24.11.3. Discussion
      4. 24.11.4. See Also
    13. 24.12. Program: Web Server Directory Listing
    14. 24.13. Program: Site Search
  28. 25. Command-Line PHP
    1. 25.0. Introduction
    2. 25.1. Parsing Program Arguments
      1. 25.1.1. Problem
      2. 25.1.2. Solution
      3. 25.1.3. Discussion
      4. 25.1.4. See Also
    3. 25.2. Parsing Program Arguments with getopt
      1. 25.2.1. Problem
      2. 25.2.2. Solution
      3. 25.2.3. Discussion
      4. 25.2.4. See Also
    4. 25.3. Reading from the Keyboard
      1. 25.3.1. Problem
      2. 25.3.2. Solution
      3. 25.3.3. Discussion
      4. 25.3.4. See Also
    5. 25.4. Running PHP Code on Every Line of an Input File
      1. 25.4.1. Problem
      2. 25.4.2. Solution
      3. 25.4.3. Discussion
      4. 25.4.4. See Also
    6. 25.5. Reading Passwords
      1. 25.5.1. Problem
      2. 25.5.2. Solution
      3. 25.5.3. Discussion
      4. 25.5.4. See Also
    7. 25.6. Program: Command Shell
  29. 26. PEAR and PECL
    1. 26.0. Introduction
    2. 26.1. Using the PEAR Installer
      1. 26.1.1. Problem
      2. 26.1.2. Solution
      3. 26.1.3. Discussion
      4. 26.1.4. See Also
    3. 26.2. Finding PEAR Packages
      1. 26.2.1. Problem
      2. 26.2.2. Solution
      3. 26.2.3. Discussion
      4. 26.2.4. See Also
    4. 26.3. Finding Information About a Package
      1. 26.3.1. Problem
      2. 26.3.2. Solution
      3. 26.3.3. Discussion
      4. 26.3.4. See Also
    5. 26.4. Installing PEAR Packages
      1. 26.4.1. Problem
      2. 26.4.2. Solution
      3. 26.4.3. Discussion
      4. 26.4.4. See Also
    6. 26.5. Upgrading PEAR Packages
      1. 26.5.1. Problem
      2. 26.5.2. Solution
      3. 26.5.3. Discussion
      4. 26.5.4. See Also
    7. 26.6. Uninstalling PEAR Packages
      1. 26.6.1. Problem
      2. 26.6.2. Solution
      3. 26.6.3. Discussion
      4. 26.6.4. See Also
    8. 26.7. Installing PECL Packages
      1. 26.7.1. Problem
      2. 26.7.2. Solution
      3. 26.7.3. Discussion
      4. 26.7.4. See Also
  30. Index
  31. About the Authors
  32. Colophon
  33. Copyright