You are previewing PHP Phrasebook: Essential Code and Commands.
O'Reilly logo
PHP Phrasebook: Essential Code and Commands

Book Description

If you were traveling in Spain, but couldn't speak Spanish very well, you'd probably carry a Spanish dictionary with you. If you are a PHP developer who needs a portable reference guide for frequent use in your job, the PHP Phrasebook is perfect for you. The PHP Phrasebook is actually a pocket guide that is jam-packed with useful and essential PHP code "phrases" for the PHP developer's everyday use. The code is flexible, so it can be easily adapted to your needs and mulitple situations, and your time isn't wasted wading through chapters of tutorial lessons and extraneous information. The phrasebook covers PHP 5 and is relevant for PHP 4.

Table of Contents

  1. Copyright
  2. About the Author
  3. We Want to Hear from You!
  4. Reader Services
  5. Introduction
  6. 1. Manipulating Strings
    1. Comparing Strings
    2. Checking Usernames and Passwords
    3. Converting Strings into Hypertext Markup Language (HTML)
    4. Using Line Breaks
    5. Encrypting Strings
    6. Checksumming Strings
    7. Extracting Substrings
    8. Protecting Email Addresses Using ASCII Codes
      1. Printing Strings, Variables, and Expressions Simultaneously
    9. Scanning Formatted Strings
    10. Getting Detailed Information About Variables
    11. Searching in Strings
      1. Understanding Regular Expressions
    12. Using POSIX Regular Expressions
    13. Using Perl-Compatible Regular Expressions
    14. Finding Tags with Regular Expressions
    15. Validating Mandatory Input
    16. Validating Numbers (and Other Data Types)
    17. Validating Email Addresses
    18. Search and Replace
  7. 2. Working with Arrays
    1. Accessing All Elements of Numerical Arrays
    2. Accessing All Elements of Associative Arrays
    3. Accessing All Array Elements in Nested Arrays
    4. Turning an Array into Variables
    5. Converting Strings to Arrays
    6. Converting Arrays to Strings
    7. Sorting Arrays Alphabetically
    8. Sorting Associative Arrays Alphabetically
    9. Sorting Nested Arrays
    10. Sorting Nested Associative Arrays
    11. Sorting IP Addresses (as a Human Would)
    12. Sorting Anything
    13. Sorting with Foreign Languages
    14. Applying an Effect to All Array Elements
    15. Filtering Arrays
    16. Getting Random Elements Out of Arrays
  8. 3. Date and Time
    1. Using Text Within date()
    2. Automatically Localizing Dates
    3. Manually Localizing Dates
    4. Using the Current Date the U.S./U.K./European Way
    5. Formatting a Specific Date
    6. Validating a Date
    7. Calculating a Relative Date
    8. Creating a Sortable Time Stamp
    9. Converting a String into a Date
    10. Determining Sunrise and Sunset
    11. Using Date and Time for Benchmarks
    12. Using Form Fields for Date Selection
    13. Create Self-updating Form Fields for Date Selection
    14. Calculating the Difference Between Two Dates
    15. Using GMT Date/Time Information
  9. 4. Interacting with Web Forms
    1. Sending Form Data Back to the Current Script
    2. Reading Out Form Data
    3. Coping with “Magic Quotes”
    4. Checking Whether a Form Has Been Submitted
    5. Saving Form Data into a Cookie
    6. Prefilling Text Fields and Password Fields
    7. Prefilling Multiline Text Fields
    8. Preselecting Radio Buttons
    9. Preselecting Check Boxes
    10. Preselecting Selection Lists
    11. Preselecting Multiple Selection Lists
    12. Processing Graphical Submit Buttons
    13. Checking Mandatory Fields
    14. Checking Selection Lists
    15. Writing All Form Data into a File
    16. Sending All Form Data Via Email
    17. Getting Information About File Uploads
    18. Moving Uploaded Files to a Safe Location
  10. 5. Remembering Users (Cookies and Sessions)
    1. Understanding Cookies
    2. Creating a Cookie
    3. Reading Out Cookies
    4. Getting Rid of “Magic Quotes” in Cookies
    5. Setting a (Reasonable) Expiry Date
    6. Setting a Client-Specific Expiry Date
    7. Deleting a Cookie
    8. Making Cookies Accessible for Several Domains
    9. Checking Whether the Client Supports Cookies
    10. Saving Multiple Data in One Cookie
    11. Saving the User's Language Preference
    12. Understanding Sessions
    13. Where to Store the Sessions
    14. How to Maintain the Session State
    15. Activating Sessions
    16. Reading and Writing Sessions
    17. Closing Sessions
    18. Changing the Session ID
    19. Creating Dynamic, Session-Aware Links
    20. Implementing a Custom Session Management
    21. Creating a Secured Area with Sessions
    22. Creating a Secured Area Without Sessions
  11. 6. Using Files on the Server File System
    1. Opening and Closing Files
    2. Reading from Files
    3. Writing to Files
    4. Locking Files
    5. Using Relative Paths for File Access
    6. Avoiding Security Traps with File Access
    7. Working with CSV Data
    8. Parsing INI Files
    9. Retrieving File Information
    10. Copying, Moving, and Deleting Files
    11. Browsing the File System
    12. Using PHP Streams
    13. Using Bzip2 Archives
    14. Returning Files with an HTTP Request
  12. 7. Making Data Dynamic
    1. Connecting to MySQL
    2. Connecting to MySQLi
    3. Sending SQL to MySQL
    4. Prepared Statements with MySQL
    5. Retrieving Results of a Query to MySQL
    6. Connecting to SQLite
    7. Sending SQL to SQLite
    8. Retrieving Results of a Query to SQLite
    9. Connecting to PostgreSQL
    10. Sending SQL to PostgreSQL
    11. Updating Data in PostgreSQL
    12. Retrieving Results of a Query to PostgreSQL
    13. Connecting to Oracle
    14. Sending SQL to Oracle
    15. Retrieving Results of a Query to Oracle
    16. Connecting to MSSQL
    17. Sending SQL to MSSQL
    18. Retrieving Results of a Query to MSSQL
    19. Connecting to Firebird
    20. Sending SQL to Firebird
    21. Retrieving Results of a Query to Firebird
    22. Connecting Via PDO
    23. Sending SQL Via PDO
    24. Retrieving Results of a Query Via PDO
  13. 8. Using XML
    1. Parsing XML with SAX
    2. Using DOM in PHP 4 to Read XML
    3. Using DOM in PHP 5 to Read XML
    4. Using DOM in PHP 4 to Write XML
    5. Using DOM in PHP 5 to Write XML
    6. Using SimpleXML
    7. Transforming XML with XSL and PHP 4
    8. Transforming XML with XSL and PHP 5
    9. Validating XML
  14. 9. Communicating with Others
    1. Connecting with HTTP Servers
    2. Connecting with FTP Servers
    3. Checking Whether a Server Is Still Reacting
      1. Understanding Web Services
    4. Creating a Web Service with PEAR::XML-RPC
    5. Consuming a Web Service with PEAR::XML-RPC
    6. Creating a Web Service with NuSOAP
    7. Automatically Generating WSDL with NuSOAP
    8. Consuming a Web Service with NuSOAP
    9. Creating a Web Service with PEAR::SOAP
    10. Automatically Generating WSDL with PEAR::SOAP
    11. Consuming a Web Service with PEAR::SOAP
    12. Creating a Web Service with PHP 5's SOAP Extension
      1. Automatically Generating WSDL with PHP 5's SOAP Extension
    13. Consuming a Web Service with PHP 5's SOAP Extension
      1. Using the Worst Acronym Ever: AJAX