You are previewing Sams Teach Yourself PHP in 10 Minutes.
O'Reilly logo
Sams Teach Yourself PHP in 10 Minutes

Book Description

Are you one of those people who think there isn't anything substantial that you can do in only 10 minutes? Think again. Sams Teach Yourself PHP in 10 Minutes is a no-fluff, just-the-answers guide to building dynamic websites using PHP. Broken into 10 minute lessons, you will gain a rapid working knowledge of PHP 5 and be able to immediately put that knowledge to use in practical applications. Who ever would have thought there was so much you could do in just 10 minutes!

Table of Contents

  1. Copyright
  2. About the Author
  3. We Want to Hear from You!
  4. Reader Services
  5. Introduction: Welcome to PHP
    1. Who This Book Is For
    2. How This Book Is Organized
      1. Part I: PHP Foundations
      2. Part II: Working with Data
      3. Part III: The Web Environment
      4. Part IV: Using Other Services from PHP
      5. Part V: Configuring and Extending PHP
    3. Versions of Software Covered
    4. Conventions Used in This Book
  6. 1. Getting to Know PHP
    1. PHP Basics
      1. Server-Side Scripting
      2. PHP Tags
    2. Your First Script
      1. The echo Command
      2. Comments
    3. Summary
  7. 2. Variables
    1. Understanding Variables
      1. Naming Variables
      2. Expressions
      3. Variables in Strings
    2. Data Types
      1. Type Juggling
      2. Variable Variables
    3. Summary
  8. 3. Flow Control
    1. Conditional Statements
      1. Conditional Operators
      2. Logical Operators
      3. Multiple Condition Branches
      4. The switch Statement
    2. Loops
      1. The while Loop
      2. The do Loop
      3. The for Loop
      4. Nesting Conditions and Loops
      5. Breaking Out of a Loop
    3. Summary
  9. 4. Functions
    1. Using Functions
      1. Defining Functions
    2. Arguments and Return Values
      1. Returning Success or Failure
      2. Default Argument Values
      3. Variable Scope
    3. Using Library Files
      1. Including Library Files
    4. Summary
  10. 5. Working with Numbers
    1. Arithmetic
      1. Arithmetic Operators
      2. Incrementing and Decrementing
      3. Compound Operators
      4. Operator Precedence
    2. Numeric Data Types
      1. Understanding NULLs
    3. Numeric Functions
      1. Rounding Numbers
      2. Comparisons
      3. Random Numbers
      4. Mathematical Functions
    4. Summary
  11. 6. Working with Strings
    1. Anatomy of a String
      1. Escaping Characters with Backslash
      2. Concatenation
      3. Comparing Strings
    2. Formatting Strings
      1. Using printf
      2. Format Codes
      3. Using sprintf
    3. String Functions
      1. Capitalization
      2. Dissecting a String
    4. Summary
  12. 7. Working with Arrays
    1. What Is an Array?
      1. Creating and Accessing Arrays
      2. Outputting the Contents of an Array
      3. Looping Through an Array
      4. Associative Arrays
    2. Array Functions
      1. Sorting
      2. Randomizing an Array
      3. Set Functions
      4. Looking Inside Arrays
      5. Serializing
    3. Multidimensional Arrays
      1. Accessing Two-Dimensional Data
      2. Defining a Multidimensional Array
    4. Summary
  13. 8. Regular Expressions
    1. Introducing Regular Expressions
      1. Types of Regular Expression
    2. Using ereg
      1. Testing Sets of Characters
      2. Common Character Classes
      3. Testing for Position
      4. Wildcard Matching
      5. Repeating Patterns
      6. Some Practical Examples
        1. Zip Codes
        2. Telephone Numbers
        3. Email Addresses
      7. Breaking a String into Components
      8. Searching and Replacing
    3. Summary
  14. 9. Working with Dates and Times
    1. Date Formats
      1. Do-It-Yourself Date Formats
      2. Unix Timestamp Format
    2. Working with Timestamps
      1. Formatting Dates
      2. Creating Timestamps
      3. Converting Other Date Formats to Timestamps
      4. Getting Information About a Timestamp
    3. Summary
  15. 10. Using Classes
    1. Object-Oriented PHP
    2. What Is a Class?
      1. When to Use Classes
      2. What a Class Looks Like
    3. Creating and Using Objects
      1. Methods and Properties
      2. Using a Third-Party Class
    4. Summary
  16. 11. Processing HTML Forms
    1. Submitting a Form to PHP
      1. The <FORM> Tag
      2. The <INPUT> Tag
      3. The <TEXTAREA> Tag
      4. The <SELECT> Tag
      5. Putting It All Together
    2. Processing a Form with PHP
      1. Accessing Form Values
      2. Hidden Inputs
    3. Creating a Form Mail Script
      1. The mail Function
    4. Summary
  17. 12. Generating Dynamic HTML
    1. Setting Default Values
      1. Default Input Values
      2. Checking a Check Box
      3. Selecting a Radio Button Group Item
      4. Defaulting a Selection in a Menu
    2. Creating Form Elements
      1. Creating a Dynamic Radio Button Group
      2. Creating a Dynamic Menu
      3. Multiple Selection Items
    3. Summary
  18. 13. Form Validation
    1. Enforcing Required Fields
    2. Displaying Validation Warnings
    3. Enforcing Data Rules
    4. Highlighting Fields That Require Attention
    5. Summary
  19. 14. Cookies and Sessions
    1. Cookies
      1. Cookie Ingredients
      2. Accessing Cookies
      3. Making Cookies with PHP
      4. Deleting Cookies
    2. Sessions
      1. Creating a Session
      2. Using Session Variables
    3. Summary
  20. 15. User Authentication
    1. Types of Authentication
      1. Basic HTTP Authentication
      2. Session-Based Authentication
    2. Building an Authentication System
      1. How the System Works
      2. Authenticating a Login
      3. Encrypting Passwords
      4. Usability Considerations
    3. Summary
  21. 16. Communicating with the Web Server
    1. HTTP Headers
      1. Sending Custom Headers
      2. Redirection Headers
      3. Checking Whether Headers Have Been Sent
      4. Displaying HTTP Headers
      5. Changing Cache Settings
    2. Server Environment Variables
      1. Script Information
      2. User Information
      3. Server Information
    3. Summary
  22. 17. Filesystem Access
    1. Managing Files
      1. File Permissions
      2. Getting Information About a File
      3. Moving and Copying Files
      4. Working with Filenames
    2. Reading and Writing Files
      1. Simple Methods for Reading and Writing Files
      2. Lower-Level File Access
      3. Random Access to Files
      4. Writing to a File Pointer
      5. Working with Data Files
      6. Working with URLs
      7. Working with Directories
    3. Summary
  23. 18. Host Program Execution
    1. Executing Host Programs
      1. The passthru Function
      2. Using Backticks
      3. Building Command Strings
    2. The Host Environment
      1. Detecting the Host Platform
      2. Environment Variables
      3. Time Zones
    3. Security Considerations
      1. Escaping Shell Commands
    4. Summary
  24. 19. Using a MySQL Database
    1. Using MySQL
      1. Connecting to a MySQL Database
    2. Executing SQL Statements
      1. Commands That Change a Database
      2. Fetching Queried Data
      3. Fetching Full Rows of Data
    3. Debugging SQL
      1. SQL Errors
      2. Connection Errors
    4. Summary
  25. 20. Database Abstraction
    1. The PEAR DB Class
      1. Installing the DB Class
      2. Data Source Names
      3. Using the DB Class
      4. Performing a Query
      5. Retrieving Selected Data
      6. Query Shortcuts
    2. Database Portability Issues
      1. Portability Modes
      2. Working with Quotes
      3. Sequences
      4. Query Limits
    3. Summary
  26. 21. Running PHP on the Command Line
    1. The Command-Line Environment
      1. Differences Between CLI and CGI Binaries
      2. PHP Shell Scripts on Linux/Unix
      3. PHP Command Scripts on Windows
      4. Embedding PHP Code
    2. Writing Scripts for the Command Line
      1. Character Mode Output
      2. Command-Line Arguments
      3. Input/Output Streams
      4. Creating Desktop Applications
    3. Summary
  27. 22. Error Handling
    1. Error Reporting
      1. Changing Error Levels
      2. Custom Error Handlers
      3. Raising User Errors
      4. Logging Errors
      5. Suppressing Errors and Warnings
      6. The Error Suppression Operator
      7. Preventing Error Display
    2. Summary
  28. 23. PHP Configuration
    1. Configuration Settings
      1. Using php.ini
      2. Alternate php.ini Files
      3. Per-Directory Configuration
      4. Dynamic Configuration
    2. Configuration Directives
      1. Configuring the PHP Environment
        1. PHP Tag Styles
        2. System Resource Limits
        3. Form Processing
        4. Include Files
        5. Error Logging
      2. Configuring PHP Extensions
      3. Configuring System Security
    3. Loadable Modules
      1. Loading Extensions on Demand
      2. Loading Modules on Startup
    4. Summary
  29. 24. PHP Security
    1. Safe Mode
      1. Restrictions Enforced by Safe Mode
      2. Enabling Safe Mode
    2. Other Security Features
      1. Hiding PHP
      2. Filesystem Security
      3. Function Access Control
      4. Database Security
    3. Summary
  30. 25. Using PEAR
    1. Introducing PEAR
      1. The PEAR Code Library
      2. Package Distribution and Maintenance
      3. PEAR Coding Standards
      4. PHP Foundation Classes
      5. Online Support for PEAR
    2. Using PEAR
      1. Finding a PEAR Package
      2. Using the PEAR Installer
      3. Contributing Your Own PEAR Project
    3. Summary
  31. A. Installing PHP
    1. Linux/Unix Installation
      1. Compiling Apache from Source
      2. Compiling and Installing PHP
    2. Windows Installation
      1. Installing Apache
      2. Installing PHP
    3. Troubleshooting