Cover image for PHP Cookbook

Book description

PHP is a simple yet powerful open source scripting language that has become a big player in web development. Over a million web sites, from large corporate sites to small personal sites, are using PHP to serve dynamic web content. PHP's broad feature set, approachable syntax, and support for different operating systems and web servers make it an ideal language for rapid web development. The PHP Cookbook is a collection of problems, solutions, and practical examples for PHP programmers. The book contains a unique and extensive collection of best practices for everyday PHP programming dilemmas. For every problem addressed in the book, there's a worked-out solution or "recipe" -- short, focused pieces of code that you can insert directly into your applications. But this book offers more than cut-and-paste code. You also get explanations of how and why the code works, so you can learn to adapt the problem-solving techniques to similar situations. The recipes in the PHP Cookbook range from simple tasks, such as sending a database query and fetching URLs, to entire programs that demonstrate complex tasks, such as printing HTML tables and generating bar charts. This book contains over 250 recipes on the following topics:

  • Working with basic data types, including strings, numbers, dates and times, and arrays

  • PHP building blocks, such as variables, functions, classes, and objects

  • Web programming, including forms, database access, and XML

  • Useful features like regular expressions, encryption and security, graphics, internationalization and localization, and Internet services

  • Working with files and directories

  • Command-line PHP and PHP-GTK

  • PEAR, the PHP Extension and Application Repository

This book contains an impressive collection of useful code for PHP programmers, from novices to advanced practitioners. Instead of poking around mailing lists, online documentation, and other sources, you can rely on the PHP Cookbook to provide quick solutions to common problems, so you can spend your time on those out-of-the-ordinary problems specific to your application.

Table of Contents

  1. PHP Cookbook
    1. 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
    2. 1. Strings
      1. Introduction
      2. 1.1. Accessing Substrings
        1. Solution
        2. Discussion
        3. See Also
      3. 1.2. Replacing Substrings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 1.3. Processing a String One Character at a Time
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 1.4. Reversing a String by Word or Character
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 1.5. Expanding and Compressing Tabs
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 1.6. Controlling Case
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 1.7. Interpolating Functions and Expressions Within Strings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 1.8. Trimming Blanks from a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 1.9. Parsing Comma-Separated Data
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 1.10. Parsing Fixed-Width Delimited Data
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 1.11. Taking Strings Apart
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 1.12. Wrapping Text at a Certain Line Length
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 1.13. Storing Binary Data in Strings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    3. 2. Numbers
      1. Introduction
      2. 2.1. Checking Whether a String Contains a Valid Number
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 2.2. Comparing Floating-Point Numbers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 2.3. Rounding Floating-Point Numbers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 2.4. Operating on a Series of Integers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 2.5. Generating Random Numbers Within a Range
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 2.6. Generating Biased Random Numbers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 2.7. Taking Logarithms
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 2.8. Calculating Exponents
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 2.9. Formatting Numbers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 2.10. Printing Correct Plurals
        1. Problem
        2. Solution
        3. Discussion
      12. 2.11. Calculating Trigonometric Functions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 2.12. Doing Trigonometry in Degrees, not Radians
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 2.13. Handling Very Large or Very Small Numbers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 2.14. Converting Between Bases
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 2.15. Calculating Using Numbers in Bases Other Than Decimal
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    4. 3. Dates and Times
      1. Introduction
      2. 3.1. Finding the Current Date and Time
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 3.2. Converting Time and Date Parts to an Epoch Timestamp
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 3.3. Converting an Epoch Timestamp to Time and Date Parts
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 3.4. Printing a Date or Time in a Specified Format
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 3.5. Finding the Difference of Two Dates
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 3.6. Finding the Difference of Two Dates with Julian Days
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 3.7. Finding the Day in a Week, Month, Year, or the Week Number in a Year
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 3.8. Validating a Date
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 3.9. Parsing Dates and Times from Strings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 3.10. Adding to or Subtracting from a Date
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 3.11. Calculating Time with Time Zones
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 3.12. Accounting for Daylight Saving Time
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 3.13. Generating a High-Precision Time
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 3.14. Generating Time Ranges
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 3.15. Using Non-Gregorian Calendars
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 3.16. Program: Calendar
    5. 4. Arrays
      1. Introduction
      2. 4.1. Specifying an Array Not Beginning at Element 0
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 4.2. Storing Multiple Elements per Key in an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 4.3. Initializing an Array to a Range of Integers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 4.4. Iterating Through an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 4.5. Deleting Elements from an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 4.6. Changing Array Size
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 4.7. Appending One Array to Another
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 4.8. Turning an Array into a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 4.9. Printing an Array with Commas
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 4.10. Checking if a Key Is in an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 4.11. Checking if an Element Is in an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 4.12. Finding the Position of an Element in an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 4.13. Finding Elements That Pass a Certain Test
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 4.14. Finding the Largest or Smallest Valued Element in an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 4.15. Reversing an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 4.16. Sorting an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      18. 4.17. Sorting an Array by a Computable Field
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      19. 4.18. Sorting Multiple Arrays
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      20. 4.19. Sorting an Array Using a Method Instead of a Function
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      21. 4.20. Randomizing an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      22. 4.21. Shuffling a Deck of Cards
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      23. 4.22. Removing Duplicate Elements from an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      24. 4.23. Finding the Union, Intersection, or Difference of Two Arrays
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      25. 4.24. Finding All Element Combinations of an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      26. 4.25. Finding All Permutations of an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      27. 4.26. Program: Printing an Array in a Horizontally Columned HTML Table
    6. 5. Variables
      1. Introduction
      2. 5.1. Avoiding == Versus = Confusion
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 5.2. Establishing a Default Value
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 5.3. Exchanging Values Without Using Temporary Variables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 5.4. Creating a Dynamic Variable Name
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 5.5. Using Static Variables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 5.6. Sharing Variables Between Processes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 5.7. Encapsulating Complex Data Types as a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 5.8. Dumping Variable Contents as Strings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    7. 6. Functions
      1. Introduction
      2. 6.1. Accessing Function Parameters
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 6.2. Setting Default Values for Function Parameters
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 6.3. Passing Values by Reference
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 6.4. Using Named Parameters
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 6.5. Creating Functions That Take a Variable Number of Arguments
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 6.6. Returning Values by Reference
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 6.7. Returning More Than One Value
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 6.8. Skipping Selected Return Values
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 6.9. Returning Failure
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 6.10. Calling Variable Functions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 6.11. Accessing a Global Variable Inside a Function
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 6.12. Creating Dynamic Functions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    8. 7. Classes and Objects
      1. Introduction
      2. 7.1. Instantiating Objects
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 7.2. Defining Object Constructors
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 7.3. Destroying an Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 7.4. Cloning Objects
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 7.5. Assigning Object References
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 7.6. Calling Methods on an Object Returned by Another Method
        1. Problem
        2. Solution
        3. Discussion
      8. 7.7. Accessing Overridden Methods
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 7.8. Using Property Overloading
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 7.9. Using Method Polymorphism
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 7.10. Finding the Methods and Properties of an Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 7.11. Adding Properties to a Base Object
        1. Problem
        2. Solution
        3. Discussion
      13. 7.12. Creating a Class Dynamically
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 7.13. Instantiating an Object Dynamically
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    9. 8. Web Basics
      1. Introduction
      2. 8.1. Setting Cookies
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 8.2. Reading Cookie Values
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 8.3. Deleting Cookies
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 8.4. Redirecting to a Different Location
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 8.5. Using Session Tracking
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 8.6. Storing Sessions in a Database
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 8.7. Detecting Different Browsers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 8.8. Building a GET Query String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 8.9. Using HTTP Basic Authentication
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 8.10. Using Cookie Authentication
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 8.11. Flushing Output to the Browser
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 8.12. Buffering Output to the Browser
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 8.13. Compressing Web Output with gzip
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 8.14. Hiding Error Messages from Users
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 8.15. Tuning Error Handling
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 8.16. Using a Custom Error Handler
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      18. 8.17. Logging Errors
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      19. 8.18. Eliminating “headers already sent” Errors
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      20. 8.19. Logging Debugging Information
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      21. 8.20. Reading Environment Variables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      22. 8.21. Setting Environment Variables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      23. 8.22. Reading Configuration Variables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      24. 8.23. Setting Configuration Variables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      25. 8.24. Communicating Within Apache
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      26. 8.25. Profiling Code
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      27. 8.26. Program: Website Account (De)activator
      28. 8.27. Program: Abusive User Checker
    10. 9. Forms
      1. Introduction
      2. 9.1. Processing Form Input
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 9.2. Validating Form Input
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 9.3. Working with Multipage Forms
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 9.4. Redisplaying Forms with Preserved Information and Error Messages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 9.5. Guarding Against Multiple Submission of the Same Form
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 9.6. Processing Uploaded Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 9.7. Securing PHP’s Form Processing
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 9.8. Escaping Control Characters from User Data
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 9.9. Handling Remote Variables with Periods in Their Names
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 9.10. Using Form Elements with Multiple Options
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 9.11. Creating Dropdown Menus Based on the Current Date
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    11. 10. Database Access
      1. Introduction
      2. 10.1. Using Text-File Databases
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 10.2. Using DBM Databases
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 10.3. Connecting to a SQL Database
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 10.4. Querying a SQL Database
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 10.5. Retrieving Rows Without a Loop
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 10.6. Modifying Data in a SQL Database
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 10.7. Repeating Queries Efficiently
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 10.8. Finding the Number of Rows Returned by a Query
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 10.9. Escaping Quotes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 10.10. Logging Debugging Information and Errors
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 10.11. Assigning Unique ID Values Automatically
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 10.12. Building Queries Programmatically
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 10.13. Making Paginated Links for a Series of Records
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 10.14. Caching Queries and Results
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 10.15. Program: Storing a Threaded Message Board
    12. 11. Web Automation
      1. Introduction
      2. 11.1. Fetching a URL with the GET Method
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 11.2. Fetching a URL with the POST Method
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 11.3. Fetching a URL with Cookies
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 11.4. Fetching a URL with Headers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 11.5. Fetching an HTTPS URL
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 11.6. Debugging the Raw HTTP Exchange
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 11.7. Marking Up a Web Page
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 11.8. Extracting Links from an HTML File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 11.9. Converting ASCII to HTML
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 11.10. Converting HTML to ASCII
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 11.11. Removing HTML and PHP Tags
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 11.12. Using Smarty Templates
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 11.13. Parsing a Web Server Log File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 11.14. Program: Finding Stale Links
      16. 11.15. Program: Finding Fresh Links
    13. 12. XML
      1. Introduction
      2. 12.1. Generating XML Manually
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 12.2. Generating XML with the DOM
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 12.3. Parsing XML with the DOM
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 12.4. Parsing XML with SAX
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 12.5. Transforming XML with XSLT
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 12.6. Sending XML-RPC Requests
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 12.7. Receiving XML-RPC Requests
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 12.8. Sending SOAP Requests
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 12.9. Receiving SOAP Requests
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 12.10. Exchanging Data with WDDX
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 12.11. Reading RSS Feeds
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    14. 13. Regular Expressions
      1. Introduction
      2. 13.1. Switching From ereg to preg
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 13.2. Matching Words
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 13.3. Finding the nth Occurrence of a Match
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 13.4. Choosing Greedy or Nongreedy Matches
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 13.5. Matching a Valid Email Address
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 13.6. Finding All Lines in a File That Match a Pattern
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 13.7. Capturing Text Inside HTML Tags
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 13.8. Escaping Special Characters in a Regular Expression
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 13.9. Reading Records with a Pattern Separator
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    15. 14. Encryption and Security
      1. Introduction
      2. 14.1. Keeping Passwords Out of Your Site Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 14.2. Obscuring Data with Encoding
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 14.3. Verifying Data with Hashes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 14.4. Storing Passwords
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 14.5. Checking Password Strength
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 14.6. Dealing with Lost Passwords
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 14.7. Encrypting and Decrypting Data
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 14.8. Storing Encrypted Data in a File or Database
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 14.9. Sharing Encrypted Data with Another Web Site
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 14.10. Detecting SSL
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 14.11. Encrypting Email with GPG
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    16. 15. Graphics
      1. Introduction
      2. 15.1. Drawing Lines, Rectangles, and Polygons
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 15.2. Drawing Arcs, Ellipses, and Circles
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 15.3. Drawing with Patterned Lines
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 15.4. Drawing Text
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 15.5. Drawing Centered Text
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 15.6. Building Dynamic Images
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 15.7. Getting and Setting a Transparent Color
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 15.8. Serving Images Securely
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 15.9. Program: Generating Bar Charts from Poll Results
    17. 16. Internationalization and Localization
      1. Introduction
      2. 16.1. Listing Available Locales
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 16.2. Using a Particular Locale
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 16.3. Setting the Default Locale
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 16.4. Localizing Text Messages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 16.5. Localizing Dates and Times
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 16.6. Localizing Currency Values
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 16.7. Localizing Images
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 16.8. Localizing Included Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 16.9. Managing Localization Resources
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 16.10. Using gettext
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 16.11. Reading or Writing Unicode Characters
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    18. 17. Internet Services
      1. Introduction
      2. 17.1. Sending Mail
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 17.2. Sending MIME Mail
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 17.3. Reading Mail with IMAP or POP3
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 17.4. Posting Messages to Usenet Newsgroups
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 17.5. Reading Usenet News Messages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 17.6. Getting and Putting Files with FTP
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 17.7. Looking Up Addresses with LDAP
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 17.8. Using LDAP for User Authentication
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 17.9. Performing DNS Lookups
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 17.10. Checking if a Host Is Alive
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 17.11. Getting Information About a Domain Name
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    19. 18. Files
      1. Introduction
      2. 18.1. Creating or Opening a Local File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 18.2. Creating a Temporary File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 18.3. Opening a Remote File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 18.4. Reading from Standard Input
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 18.5. Reading a File into a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 18.6. Counting Lines, Paragraphs, or Records in a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 18.7. Processing Every Word in a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 18.8. Reading a Particular Line in a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 18.9. Processing a File Backward by Line or Paragraph
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 18.10. Picking a Random Line from a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 18.11. Randomizing All Lines in a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 18.12. Processing Variable Length Text Fields
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 18.13. Reading Configuration Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 18.14. Reading from or Writing to a Specific Location in a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 18.15. Removing the Last Line of a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 18.16. Modifying a File in Place Without a Temporary File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      18. 18.17. Flushing Output to a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      19. 18.18. Writing to Standard Output
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      20. 18.19. Writing to Many Filehandles Simultaneously
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      21. 18.20. Escaping Shell Metacharacters
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      22. 18.21. Passing Input to a Program
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      23. 18.22. Reading Standard Output from a Program
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      24. 18.23. Reading Standard Error from a Program
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      25. 18.24. Locking a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      26. 18.25. Reading and Writing Compressed Files
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      27. 18.26. Program: Unzip
        1. See Also
    20. 19. Directories
      1. Introduction
      2. 19.1. Getting and Setting File Timestamps
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 19.2. Getting File Information
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 19.3. Changing File Permissions or Ownership
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 19.4. Splitting a Filename into Its Component Parts
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 19.5. Deleting a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 19.6. Copying or Moving a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 19.7. Processing All Files in a Directory Recursively
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 19.8. Getting a List of Filenames Matching a Pattern
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 19.9. Processing All Files in a Directory
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 19.10. Making New Directories
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 19.11. Removing a Directory and Its Contents
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 19.12. Program: Web Server Directory Listing
      14. 19.13. Program: Site Search
    21. 20. Client-Side PHP
      1. Introduction
      2. 20.1. Parsing Program Arguments
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 20.2. Parsing Program Arguments with getopt
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 20.3. Reading from the Keyboard
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 20.4. Reading Passwords
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 20.5. Displaying a GUI Widget in a Window
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 20.6. Displaying Multiple GUI Widgets in a Window
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 20.7. Responding to User Actions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 20.8. Displaying Menus
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 20.9. Program: Command Shell
      11. 20.10. Program: Displaying Weather Conditions
    22. 21. PEAR
      1. Introduction
      2. 21.1. Using the PEAR Package Manager
        1. Problem
        2. Solution
        3. Discussion
      3. 21.2. Finding PEAR Packages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 21.3. Finding Information About a Package
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 21.4. Installing PEAR Packages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 21.5. Installing PECL Packages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 21.6. Upgrading PEAR Packages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 21.7. Uninstalling PEAR Packages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 21.8. Documenting Classes with PHPDoc
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    23. Index
    24. Colophon