You are previewing Beginning PHP 5.3.
O'Reilly logo
Beginning PHP 5.3

Book Description

Serving as a complete introduction to PHP 5.3, this book walks you through all the major concepts of PHP in a way that's easy to follow, with plenty of code snippets illustrating each concept to aid learning. You'll discover how to install and configure PHP 5.3, how to get started with simple programs, and the basic building blocks of PHP such as variables, operators, expressions, arrays, and objects. Coverage working with files, XML, and MySQL; building Web applications with PHP; exploring the PEAR library; handling e-mail; and creating Web graphics.

Table of Contents

  1. Copyright
  2. About the Author
  3. Credits
  4. Acknowledgments
  5. Introduction
    1. Who This Book Is For
    2. What This Book Covers
    3. How This Book Is Structured
    4. What You Need to Use This Book
    5. Using the Command Line
    6. Conventions
    7. Source Code
    8. Errata
    9. p2p.wrox.com
  6. I. Getting Up and Running with PHP
    1. 1. Introducing PHP
      1. 1.1. What Is PHP?
      2. 1.2. Why Use PHP?
      3. 1.3. The Evolution of PHP
      4. 1.4. What's New in PHP 5.3
        1. 1.4.1. Namespaces
        2. 1.4.2. The goto Operator
        3. 1.4.3. Nowdoc Syntax
        4. 1.4.4. Shorthand Form of the Ternary Operator
        5. 1.4.5. Advanced Changes
      5. 1.5. Summary
    2. 2. Your First PHP Script
      1. 2.1. Installing PHP
        1. 2.1.1. Installing on Ubuntu Linux
        2. 2.1.2. Installing on Windows
        3. 2.1.3. Installing on Mac OS X
        4. 2.1.4. Testing Your Installation
          1. 2.1.4.1. Testing the Web Server
          2. 2.1.4.2. Testing PHP
        5. 2.1.5. Setting Your Time Zone
      2. 2.2. Other Ways to Run PHP
        1. 2.2.1. Running PHP with other Web Servers
        2. 2.2.2. Compiling PHP Yourself
        3. 2.2.3. Running PHP Remotely
      3. 2.3. Creating Your First Script
        1. 2.3.1. Embedding PHP within HTML
        2. 2.3.2. Enhancing the Script Further
        3. 2.3.3. Using Comments to Make Code More Readable
      4. 2.4. Summary
      5. 2.5. Exercise
  7. II. Learning the Language
    1. 3. PHP Language Basics
      1. 3.1. Using Variables in PHP
        1. 3.1.1. Naming Variables
        2. 3.1.2. Creating Variables
      2. 3.2. Understanding Data Types
        1. 3.2.1. About Loose Typing
        2. 3.2.2. Testing the Type of a Variable
        3. 3.2.3. Changing a Variable's Data Type
        4. 3.2.4. Changing Type by Casting
      3. 3.3. Operators and Expressions
        1. 3.3.1. Operator Types
          1. 3.3.1.1. Arithmetic Operators
          2. 3.3.1.2. Assignment Operators
          3. 3.3.1.3. Bitwise Operators
          4. 3.3.1.4. Comparison Operators
          5. 3.3.1.5. Incrementing/Decrementing Operators
          6. 3.3.1.6. Logical Operators
          7. 3.3.1.7. String Operators
        2. 3.3.2. Understanding Operator Precedence
      4. 3.4. Constants
      5. 3.5. Summary
      6. 3.6. Exercises
    2. 4. Decisions and Loops
      1. 4.1. Making Decisions
        1. 4.1.1. Simple Decisions with the if Statement
        2. 4.1.2. Providing an Alternative Choice with the else Statement
        3. 4.1.3. Testing One Expression Many Times with the switch Statement
        4. 4.1.4. Compact Coding with the Ternary Operator
      2. 4.2. Doing Repetitive Tasks with Looping
        1. 4.2.1. Simple Looping with the while Statement
        2. 4.2.2. Testing at the End: The do ... while Loop
        3. 4.2.3. Neater Looping with the for Statement
        4. 4.2.4. Escaping from Loops with the break Statement
        5. 4.2.5. Skipping Loop Iterations with the continue Statement
        6. 4.2.6. Creating Nested Loops
      3. 4.3. Mixing Decisions and Looping with HTML
      4. 4.4. Summary
      5. 4.5. Exercises
    3. 5. Strings
      1. 5.1. Creating and Accessing Strings
        1. 5.1.1. Including More Complex Expressions within Strings
        2. 5.1.2. Using Your Own Delimiters
        3. 5.1.3. Other Ways to Create Strings
        4. 5.1.4. Finding the Length of a String
        5. 5.1.5. Accessing Characters within a String
      2. 5.2. Searching Strings
        1. 5.2.1. Searching Strings with strstr()
        2. 5.2.2. Locating Text with strpos() and strrpos()
        3. 5.2.3. Finding the Number of Occurrences with substr_count()
        4. 5.2.4. Searching for a Set of Characters with strpbrk()
      3. 5.3. Replacing Text within Strings
        1. 5.3.1. Replacing All Occurrences using str_replace()
        2. 5.3.2. Replacing a Portion of a String with substr_replace()
        3. 5.3.3. Translating Characters with strtr()
      4. 5.4. Dealing with Upper- and Lowercase
      5. 5.5. Formatting Strings
        1. 5.5.1. General-Purpose Formatting with printf() and sprintf()
        2. 5.5.2. Using Type Specifiers
        3. 5.5.3. Specifying Signs
        4. 5.5.4. Padding the Output
        5. 5.5.5. Specifying Number Precision
        6. 5.5.6. Swapping Arguments
        7. 5.5.7. Storing the Result Instead of Printing It
        8. 5.5.8. Trimming Strings with trim(), ltrim(), and rtrim()
        9. 5.5.9. Padding Strings with str_pad()
        10. 5.5.10. Wrapping Lines of Text with wordwrap()
        11. 5.5.11. Formatting Numbers with number_format()
      6. 5.6. Summary
      7. 5.7. Exercises
    4. 6. Arrays
      1. 6.1. The Anatomy of an Array
      2. 6.2. Creating Arrays
      3. 6.3. Accessing Array Elements
        1. 6.3.1. Changing Elements
        2. 6.3.2. Outputting an Entire Array with print_r()
        3. 6.3.3. Extracting a Range of Elements with array_slice()
        4. 6.3.4. Counting Elements in an Array
        5. 6.3.5. Stepping Through an Array
      4. 6.4. Looping Through Arrays with foreach
        1. 6.4.1. Using foreach to Loop Through Values
        2. 6.4.2. Using foreach to Loop Through Keys and Values
        3. 6.4.3. Altering Array Values with foreach
      5. 6.5. Working with Multidimensional Arrays
        1. 6.5.1. Creating a Multidimensional Array
        2. 6.5.2. Accessing Elements of Multidimensional Arrays
        3. 6.5.3. Looping Through Multidimensional Arrays
      6. 6.6. Manipulating Arrays
        1. 6.6.1. Sorting Arrays
        2. 6.6.2. Sorting Indexed Arrays with sort() and rsort()
        3. 6.6.3. Sorting Associative Arrays with asort() and arsort()
        4. 6.6.4. Sorting Associative Array Keys with ksort() and krsort()
        5. 6.6.5. Multi-Sorting with array_multisort()
        6. 6.6.6. Adding and Removing Array Elements
        7. 6.6.7. Adding and Removing Elements at the Start and End
        8. 6.6.8. Adding and Removing Elements in the Middle
        9. 6.6.9. Merging Arrays Together
        10. 6.6.10. Converting Between Arrays and Strings
        11. 6.6.11. Converting an Array to a List of Variables
      7. 6.7. Summary
      8. 6.8. Exercises
    5. 7. Functions
      1. 7.1. What Is a Function?
      2. 7.2. Why Functions Are Useful
      3. 7.3. Calling Functions
      4. 7.4. Working with Variable Functions
      5. 7.5. Writing Your Own Functions
        1. 7.5.1. Defining Parameters
        2. 7.5.2. Optional Parameters and Default Values
        3. 7.5.3. Returning Values from Your Functions
        4. 7.5.4. Understanding Variable Scope
          1. 7.5.4.1. Working with Global Variables
          2. 7.5.4.2. Using Static Variables to Preserve Values
        5. 7.5.5. Creating Anonymous Functions
      6. 7.6. Working with References
        1. 7.6.1. Passing References to Your Own Functions
        2. 7.6.2. Returning References from Your Own Functions
      7. 7.7. Writing Recursive Functions
      8. 7.8. Summary
      9. 7.9. Exercises
    6. 8. Objects
      1. 8.1. What Is Object-Oriented Programming?
      2. 8.2. Advantages of OOP
      3. 8.3. Understanding Basic OOP Concepts
        1. 8.3.1. Classes
        2. 8.3.2. Objects
        3. 8.3.3. Properties
        4. 8.3.4. Methods
      4. 8.4. Creating Classes and Objects in PHP
      5. 8.5. Creating and Using Properties
        1. 8.5.1. Understanding Property Visibility
        2. 8.5.2. Declaring Properties
        3. 8.5.3. Accessing Properties
        4. 8.5.4. Static Properties
        5. 8.5.5. Class Constants
      6. 8.6. Working with Methods
        1. 8.6.1. Method Visibility
        2. 8.6.2. Creating a Method
        3. 8.6.3. Calling Methods
        4. 8.6.4. Adding Parameters and Returning Values
        5. 8.6.5. Accessing Object Properties from Methods
        6. 8.6.6. Static Methods
        7. 8.6.7. Using Hints to Check Method Arguments
        8. 8.6.8. Making Your Classes Self-Contained with Encapsulation
      7. 8.7. Object Overloading with ___get(), ___set(), and ___call()
        1. 8.7.1. Overloading Property Accesses with __get() and __set()
        2. 8.7.2. Overloading Method Calls with __call()
        3. 8.7.3. Other Overloading Methods
      8. 8.8. Using Inheritance to Extend the Power of Objects
        1. 8.8.1. Overriding Methods in the Parent Class
        2. 8.8.2. Preserving the Functionality of the Parent Class
        3. 8.8.3. Blocking Inheritance and Overrides with Final Classes and Methods
        4. 8.8.4. Using Abstract Classes and Methods
        5. 8.8.5. Working with Interfaces
      9. 8.9. Constructors and Destructors
        1. 8.9.1. Setting Up New Objects with Constructors
        2. 8.9.2. Cleaning Up Objects with Destructors
      10. 8.10. Automatically Loading Class Files
      11. 8.11. Storing Objects as Strings
      12. 8.12. Determining an Object's Class
      13. 8.13. Summary
      14. 8.14. Exercises
  8. III. Using PHP in Practice
    1. 9. Handling HTML Forms with PHP
      1. 9.1. How HTML Forms Work
      2. 9.2. Capturing Form Data with PHP
        1. 9.2.1. Dealing Securely with Form Data
        2. 9.2.2. Handling Empty Form Fields
      3. 9.3. Dealing with Multi-Value Fields
      4. 9.4. Generating Web Forms with PHP
      5. 9.5. Storing PHP Variables in Forms
      6. 9.6. Creating File Upload Forms
        1. 9.6.1. Accessing Information on Uploaded Files
        2. 9.6.2. Limiting the Size of File Uploads
        3. 9.6.3. Storing and Using an Uploaded File
      7. 9.7. Redirecting after a Form Submission
      8. 9.8. Summary
      9. 9.9. Exercises
    2. 10. Preserving State With Query Strings, Cookies, and Sessions
      1. 10.1. Saving State with Query Strings
        1. 10.1.1. Building Query Strings
        2. 10.1.2. Accessing Data in Query Strings
      2. 10.2. Working with Cookies
        1. 10.2.1. Cookie Components
        2. 10.2.2. Setting a Cookie in PHP
        3. 10.2.3. Accessing Cookies in Your Scripts
        4. 10.2.4. Removing Cookies
      3. 10.3. Using PHP Sessions to Store Data
        1. 10.3.1. Creating a Session
        2. 10.3.2. Reading and Writing Session Data
        3. 10.3.3. Destroying a Session
        4. 10.3.4. Passing Session IDs in Query Strings
        5. 10.3.5. Changing Session Behavior
      4. 10.4. Summary
      5. 10.5. Exercises
    3. 11. Working with Files and Directories
      1. 11.1. Understanding Files and Directories
      2. 11.2. Getting Information on Files
        1. 11.2.1. Time-Related Properties
        2. 11.2.2. Retrieving a Filename from a Path
      3. 11.3. Opening and Closing Files
        1. 11.3.1. Opening a File with fopen()
        2. 11.3.2. Closing a File with fclose()
      4. 11.4. Reading and Writing to Files
        1. 11.4.1. Reading and Writing Strings of Characters
        2. 11.4.2. Testing for the End of a File
        3. 11.4.3. Reading One Line at a Time
        4. 11.4.4. Reading CSV Files
        5. 11.4.5. Reading and Writing Entire Files
        6. 11.4.6. Random Access to File Data
      5. 11.5. Working with File Permissions
        1. 11.5.1. Changing Permissions
        2. 11.5.2. Checking File Permissions
      6. 11.6. Copying, Renaming, and Deleting Files
      7. 11.7. Working with Directories
        1. 11.7.1. Other Directory Functions
          1. 11.7.1.1. Resetting the Directory Pointer
          2. 11.7.1.2. Changing the Current Directory
          3. 11.7.1.3. Creating Directories
          4. 11.7.1.4. Deleting Directories
          5. 11.7.1.5. Getting the Directory Path
        2. 11.7.2. Working with Directory Objects
        3. 11.7.3. Telling a File from a Directory
      8. 11.8. Building a Text Editor
        1. 11.8.1. The Text Editor Script
        2. 11.8.2. Testing the Editor
        3. 11.8.3. Examining the Editor Code
          1. 11.8.3.1. The Main Logic
          2. 11.8.3.2. The displayFileList() Function
          3. 11.8.3.3. The displayEditForm() Function
          4. 11.8.3.4. The saveFile() Function
          5. 11.8.3.5. The createFile() Function
          6. 11.8.3.6. The displayPageHeader() Function
      9. 11.9. Summary
      10. 11.10. Exercise
    4. 12. Introducing Databases and SQL
      1. 12.1. Deciding How to Store Data
        1. 12.1.1. Database Architectures
          1. 12.1.1.1. Embedded Databases
          2. 12.1.1.2. Client-Server Databases
        2. 12.1.2. Database Models
          1. 12.1.2.1. Simple Databases
          2. 12.1.2.2. Relational Databases
        3. 12.1.3. Choosing a Database
      2. 12.2. Understanding Relational Databases
        1. 12.2.1. Normalization
        2. 12.2.2. Talking to Databases with SQL
          1. 12.2.2.1. MySQL Data Types
            1. 12.2.2.1.1. Numeric Data Types
            2. 12.2.2.1.2. Date and Time Data Types
            3. 12.2.2.1.3. String Data Types
            4. 12.2.2.1.4. Using Indexes and Keys
          2. 12.2.2.2. Introducing SQL Statements
            1. 12.2.2.2.1. Understanding the NULL Value
      3. 12.3. Setting Up MySQL
        1. 12.3.1. Starting the MySQL Server
        2. 12.3.2. Setting Up the MySQL root Password
      4. 12.4. A Quick Play with MySQL
        1. 12.4.1. Creating a New Database
        2. 12.4.2. Creating a Table
        3. 12.4.3. Adding Data to a Table
        4. 12.4.4. Reading Data from a Table
        5. 12.4.5. Updating Data in a Table
        6. 12.4.6. Deleting Data from a Table
        7. 12.4.7. Deleting Tables and Databases
      5. 12.5. Connecting to MySQL from PHP
        1. 12.5.1. Making a Connection
        2. 12.5.2. Handling Errors
        3. 12.5.3. Reading Data
      6. 12.6. Summary
      7. 12.7. Exercises
    5. 13. Retrieving Data from MySQL with PHP
      1. 13.1. Setting Up the Book Club Database
        1. 13.1.1. The BINARY Attribute and Collations
        2. 13.1.2. The UNIQUE Constraint
        3. 13.1.3. The ENUM Data Type
        4. 13.1.4. The TIMESTAMP Data Type
      2. 13.2. Retrieving Data with SELECT
        1. 13.2.1. Limiting the Number of Rows Returned
        2. 13.2.2. Sorting Results
        3. 13.2.3. Using Pattern Matching for Flexible Queries
        4. 13.2.4. Summarizing Data
        5. 13.2.5. Eliminating Duplicate Results
        6. 13.2.6. Grouping Results
        7. 13.2.7. Pulling Data from Multiple Tables
        8. 13.2.8. Using Aliases
        9. 13.2.9. Other Useful MySQL Operators and Functions
      3. 13.3. Creating a Member Record Viewer
        1. 13.3.1. Creating the config.php File
        2. 13.3.2. Creating the common.inc.php File
        3. 13.3.3. Creating the DataObject Class File
        4. 13.3.4. Building the Member Class
        5. 13.3.5. Building the LogEntry Class
        6. 13.3.6. Creating the view_members.php Script
        7. 13.3.7. Creating the view_member.php Script
        8. 13.3.8. Testing the Application
      4. 13.4. Summary
      5. 13.5. Exercises
    6. 14. Manipulating MySQL Data with PHP
      1. 14.1. Inserting Records
      2. 14.2. Updating Records
      3. 14.3. Deleting Records
      4. 14.4. Building a Member Registration Application
        1. 14.4.1. Adding More Common Code
        2. 14.4.2. Enhancing the Member Class
        3. 14.4.3. Creating the Registration Script
        4. 14.4.4. Testing the Application
      5. 14.5. Creating a Members' Area
        1. 14.5.1. Adding an Authentication Method to the Member Class
        2. 14.5.2. Enhancing the LogEntry Class to Record Page Views
        3. 14.5.3. Adding More Common Code
        4. 14.5.4. Writing the Login Page Script
        5. 14.5.5. Creating a Logout Function
        6. 14.5.6. Creating the Pages for the Members' Area
        7. 14.5.7. Testing the Members' Area
      6. 14.6. Creating a Member Manager Application
        1. 14.6.1. Adding Update and Delete Methods to the Member Class
        2. 14.6.2. Adding a Deletion Method to the LogEntry Class
        3. 14.6.3. Tweaking the view_members.php Script
        4. 14.6.4. Creating the view_member.php Script
        5. 14.6.5. Testing the Member Manager
      7. 14.7. Summary
      8. 14.8. Exercises
    7. 15. Making Your Job Easier with PEAR
      1. 15.1. Installing PEAR Packages
        1. 15.1.1. Testing the PEAR Package Manager on Ubuntu
        2. 15.1.2. Testing PEAR using Mac OS X and MAMP
        3. 15.1.3. Installing and Testing PEAR with WampServer on Windows
        4. 15.1.4. Installing a Package
        5. 15.1.5. Installing Dependencies
        6. 15.1.6. Uninstalling Packages
      2. 15.2. Using a PEAR Package
      3. 15.3. Creating HTML Tables with the HTML_Table Package
      4. 15.4. Web Forms the Easy Way with HTML_QuickForm
        1. 15.4.1. Installing HTML_QuickForm
        2. 15.4.2. Working with HTML_QuickForm
        3. 15.4.3. Using Validation Rules
      5. 15.5. Summary
      6. 15.6. Exercises
    8. 16. PHP and the Outside World
      1. 16.1. Working with Dates and Times
        1. 16.1.1. Understanding Timestamps
        2. 16.1.2. Getting the Current Date and Time
        3. 16.1.3. Creating Your Own Timestamps
          1. 16.1.3.1. Creating Timestamps from Date and Time Values
          2. 16.1.3.2. Creating Timestamps from GMT Date and Time Values
          3. 16.1.3.3. Creating Timestamps from Date and Time Strings
        4. 16.1.4. Extracting Date and Time Values from a Timestamp
        5. 16.1.5. Formatting Date Strings
        6. 16.1.6. Checking Date Values
        7. 16.1.7. Working with Microseconds
        8. 16.1.8. DateTime: The Future of PHP Date/Time Handling
      2. 16.2. Working with HTTP
        1. 16.2.1. Understanding HTTP Requests
        2. 16.2.2. Exploring HTTP Responses
        3. 16.2.3. Modifying an HTTP Response
      3. 16.3. Getting Information from the Web Server
      4. 16.4. Sending Email
        1. 16.4.1. Specifying the Sender Address and Adding Headers
        2. 16.4.2. Controlling the Return Path Email Address
        3. 16.4.3. Sending HTML Emails
      5. 16.5. Summary
      6. 16.6. Exercises
    9. 17. Generating Images with PHP
      1. 17.1. Basics of Computer Graphics
        1. 17.1.1. Color Theory
        2. 17.1.2. Coordinate Systems
        3. 17.1.3. Image Types
      2. 17.2. Creating Images
        1. 17.2.1. Creating a New Image
        2. 17.2.2. Allocating Colors
        3. 17.2.3. Outputting Images
        4. 17.2.4. Drawing in an Image
          1. 17.2.4.1. Drawing Individual Pixels
          2. 17.2.4.2. Drawing Lines
          3. 17.2.4.3. Drawing Rectangles
          4. 17.2.4.4. Drawing Circles and Ellipses
          5. 17.2.4.5. Drawing an Arc
          6. 17.2.4.6. Drawing Polygons
      3. 17.3. Manipulating Images
        1. 17.3.1. Opening an Existing Image
        2. 17.3.2. Applying a Watermark
          1. 17.3.2.1. Copying the Watermark into the Image
          2. 17.3.2.2. Working with Transparency
          3. 17.3.2.3. Working with Opacity
        3. 17.3.3. Creating Thumbnails
      4. 17.4. Using Text in Images
        1. 17.4.1. Adding Standard Text
        2. 17.4.2. Using TrueType Fonts
      5. 17.5. Summary
      6. 17.6. Exercises
    10. 18. String Matching with Regular Expressions
      1. 18.1. What Is a Regular Expression?
      2. 18.2. Pattern Matching in PHP
      3. 18.3. Exploring Regular Expression Syntax
        1. 18.3.1. Matching Literal Characters
        2. 18.3.2. Matching Types of Characters Using Character Classes
        3. 18.3.3. Matching Multiple Characters
        4. 18.3.4. Greedy and Non-Greedy Matching
        5. 18.3.5. Using Subpatterns to Group Patterns
        6. 18.3.6. Referring to Previous Subpattern Matches
        7. 18.3.7. Matching Alternative Patterns
        8. 18.3.8. Using Anchors to Match At Specified Positions
      4. 18.4. Finding Multiple Matches with preg_match_all()
      5. 18.5. Searching Arrays with preg_grep()
      6. 18.6. Replacing Text
        1. 18.6.1. Replacing Text with preg_replace()
        2. 18.6.2. Replacing Text Using a Callback Function
      7. 18.7. Altering Matching Behavior with Pattern Modifiers
      8. 18.8. Splitting a String with a Regular Expression
      9. 18.9. Summary
      10. 18.10. Exercises
    11. 19. Working with XML
      1. 19.1. What Is XML?
      2. 19.2. XML Document Structure
        1. 19.2.1. Major Parts of an XML Document
        2. 19.2.2. XML Syntax Rules
        3. 19.2.3. Using XML Elements and Attributes
        4. 19.2.4. Valid XML Documents: DTDs and XSDs
        5. 19.2.5. XHTML: An Example of DTDs in Action
        6. 19.2.6. The DTDs for XHTML
        7. 19.2.7. Referencing DTDs
        8. 19.2.8. Specifying Namespaces
        9. 19.2.9. Creating an XHTML Document
      3. 19.3. Reading XML Documents with PHP
        1. 19.3.1. How XML Parser Works
        2. 19.3.2. Creating a New Parser
        3. 19.3.3. Creating Event Handlers
        4. 19.3.4. Parsing the XML Document
        5. 19.3.5. Dealing with Parse Errors
      4. 19.4. Writing and Manipulating XML Documents with PHP
        1. 19.4.1. DOM Basics
        2. 19.4.2. Creating an XML Document Using the DOM
        3. 19.4.3. Manipulating XML Documents Using the DOM
        4. 19.4.4. Adding Elements to an Existing Document
        5. 19.4.5. Removing Elements from a Document
        6. 19.4.6. Changing Nodes and Attributes
        7. 19.4.7. Moving Elements Around
      5. 19.5. Doing XML the Easy Way with SimpleXML
        1. 19.5.1. Reading an XML Document
        2. 19.5.2. Creating an XML Document
        3. 19.5.3. Converting Between SimpleXML and DOM Objects
      6. 19.6. Working with XSL and XSLT
      7. 19.7. Summary
      8. 19.8. Exercises
    12. 20. Writing High-Quality Code
      1. 20.1. Writing Modular Code
        1. 20.1.1. Including Files
        2. 20.1.2. Including a File Only Once
        3. 20.1.3. Working with Include Paths
        4. 20.1.4. Dynamic Includes
        5. 20.1.5. Using Namespaces to Avoid Clashes
      2. 20.2. Using Coding Standards for Consistency
      3. 20.3. Documenting Your Code
        1. 20.3.1. Writing Good Comments
        2. 20.3.2. Using phpDocumentor to Generate External Documentation
      4. 20.4. Checking Input and Encoding Output
        1. 20.4.1. Checking Input
        2. 20.4.2. Encoding Output
      5. 20.5. Handling Errors
        1. 20.5.1. Understanding Error Levels
        2. 20.5.2. Triggering Errors
        3. 20.5.3. Controlling Where Error Messages Are Sent
        4. 20.5.4. Logging Your Own Error Messages
        5. 20.5.5. Letting Your Script Handle Errors
        6. 20.5.6. Fine-Tuning Error Reporting
        7. 20.5.7. Using Exception Objects to Handle Errors
        8. 20.5.8. Throwing Exceptions
        9. 20.5.9. Catching Exceptions
        10. 20.5.10. Creating Your Own Exception Classes
      6. 20.6. Separating Application Logic from Presentation Logic
      7. 20.7. Automated Code Testing with PHPUnit
      8. 20.8. Summary
      9. 20.9. Exercises
    13. A. Solutions to Exercises
      1. A.1. Chapter 2
        1. A.1.1. Exercise Solution
      2. A.2. Chapter 3
        1. A.2.1. Exercise 1 Solution
        2. A.2.2. Exercise 2 Solution
      3. A.3. Chapter 4
        1. A.3.1. Exercise 1 Solution
        2. A.3.2. Exercise 2 Solution
      4. A.4. Chapter 5
        1. A.4.1. Exercise 1 Solution
        2. A.4.2. Exercise 2 Solution
      5. A.5. Chapter 6
        1. A.5.1. Exercise 1 Solution
        2. A.5.2. Exercise 2 Solution
      6. A.6. Chapter 7
        1. A.6.1. Exercise 1 Solution
        2. A.6.2. Exercise 2 Solution
      7. A.7. Chapter 8
        1. A.7.1. Exercise 1 Solution
        2. A.7.2. Exercise 2 Solution
      8. A.8. Chapter 9
        1. A.8.1. Exercise 1 Solution
        2. A.8.2. Exercise 2 Solution
      9. A.9. Chapter 10
        1. A.9.1. Exercise 1 Solution
        2. A.9.2. Exercise 2 Solution
      10. A.10. Chapter 11
        1. A.10.1. Exercise Solution
      11. A.11. Chapter 12
        1. A.11.1. Exercise 1 Solution
        2. A.11.2. Exercise 2 Solution
      12. A.12. Chapter 13
        1. A.12.1. Exercise 1 Solution
        2. A.12.2. Exercise 2 Solution
      13. A.13. Chapter 14
        1. A.13.1. Exercise 1 Solution
        2. A.13.2. Exercise 2 Solution
      14. A.14. Chapter 15
        1. A.14.1. Exercise 1 Solution
        2. A.14.2. Exercise 2 Solution
      15. A.15. Chapter 16
        1. A.15.1. Exercise 1 Solution
        2. A.15.2. Exercise 2 Solution
      16. A.16. Chapter 17
        1. A.16.1. Exercise 1 Solution
        2. A.16.2. Exercise 2 Solution
      17. A.17. Chapter 18
        1. A.17.1. Exercise 1 Solution
        2. A.17.2. Exercise 2 Solution
      18. A.18. Chapter 19
        1. A.18.1. Exercise 1 Solution
        2. A.18.2. Exercise 2 Solution
      19. A.19. Chapter 20
        1. A.19.1. Exercise 1 Solution
        2. A.19.2. Exercise 2 Solution
    14. B. Configuring PHP
      1. B.1. About php.ini
      2. B.2. php.ini Options
      3. B.3. Language Options
      4. B.4. Miscellaneous
      5. B.5. Resource Limits
      6. B.6. Error Handling and Logging
      7. B.7. Data Handling
      8. B.8. Paths and Directories
      9. B.9. File Uploads
      10. B.10. Fopen Wrappers
      11. B.11. Dynamic Extensions
      12. B.12. Module Settings
    15. C. Alternatives to MySQL
      1. C.1. SQLite
      2. C.2. PostgreSQL
      3. C.3. dbm-Style Databases
      4. C.4. Oracle
      5. C.5. ODBC
      6. C.6. Other Databases Supported by PHP
    16. D. Using PHP from the Command Line
      1. D.1. Running Command-Line PHP Scripts
      2. D.2. Passing Arguments to Command-Line Scripts
      3. D.3. Creating Interactive Scripts
      4. D.4. Scheduling PHP Command-Line Scripts
      5. D.5. Useful Command-Line Options
      6. D.6. Wrapping Up