PHP Cookbook
By
David Sklar,
Adam Trachtenberg
November 2002
Pages: 632
| Table of Contents
| Index
| Sample Chapter
| Colophon
Table of Contents
-
Chapter 1 Strings
-
Introduction
-
Accessing Substrings
-
Replacing Substrings
-
Processing a String One Character at a Time
-
Reversing a String by Word or Character
-
Expanding and Compressing Tabs
-
Controlling Case
-
Interpolating Functions and Expressions Within Strings
-
Trimming Blanks from a String
-
Parsing Comma-Separated Data
-
Parsing Fixed-Width Delimited Data
-
Taking Strings Apart
-
Wrapping Text at a Certain Line Length
-
Storing Binary Data in Strings
-
Chapter 2 Numbers
-
Introduction
-
Checking Whether a String Contains a Valid Number
-
Comparing Floating-Point Numbers
-
Rounding Floating-Point Numbers
-
Operating on a Series of Integers
-
Generating Random Numbers Within a Range
-
Generating Biased Random Numbers
-
Taking Logarithms
-
Calculating Exponents
-
Formatting Numbers
-
Printing Correct Plurals
-
Calculating Trigonometric Functions
-
Doing Trigonometry in Degrees, not Radians
-
Handling Very Large or Very Small Numbers
-
Converting Between Bases
-
Calculating Using Numbers in Bases Other Than Decimal
-
Chapter 3 Dates and Times
-
Introduction
-
Finding the Current Date and Time
-
Converting Time and Date Parts to an Epoch Timestamp
-
Converting an Epoch Timestamp to Time and Date Parts
-
Printing a Date or Time in a Specified Format
-
Finding the Difference of Two Dates
-
Finding the Difference of Two Dates with Julian Days
-
Finding the Day in a Week, Month, Year, or the Week Number in a Year
-
Validating a Date
-
Parsing Dates and Times from Strings
-
Adding to or Subtracting from a Date
-
Calculating Time with Time Zones
-
Accounting for Daylight Saving Time
-
Generating a High-Precision Time
-
Generating Time Ranges
-
Using Non-Gregorian Calendars
-
Program: Calendar
-
Chapter 4 Arrays
-
Introduction
-
Specifying an Array Not Beginning at Element 0
-
Storing Multiple Elements per Key in an Array
-
Initializing an Array to a Range of Integers
-
Iterating Through an Array
-
Deleting Elements from an Array
-
Changing Array Size
-
Appending One Array to Another
-
Turning an Array into a String
-
Printing an Array with Commas
-
Checking if a Key Is in an Array
-
Checking if an Element Is in an Array
-
Finding the Position of an Element in an Array
-
Finding Elements That Pass a Certain Test
-
Finding the Largest or Smallest Valued Element in an Array
-
Reversing an Array
-
Sorting an Array
-
Sorting an Array by a Computable Field
-
Sorting Multiple Arrays
-
Sorting an Array Using a Method Instead of a Function
-
Randomizing an Array
-
Shuffling a Deck of Cards
-
Removing Duplicate Elements from an Array
-
Finding the Union, Intersection, or Difference of Two Arrays
-
Finding All Element Combinations of an Array
-
Finding All Permutations of an Array
-
Program: Printing an Array in a Horizontally Columned HTML Table
-
Chapter 5 Variables
-
Introduction
-
Avoiding == Versus = Confusion
-
Establishing a Default Value
-
Exchanging Values Without Using Temporary Variables
-
Creating a Dynamic Variable Name
-
Using Static Variables
-
Sharing Variables Between Processes
-
Encapsulating Complex Data Types as a String
-
Dumping Variable Contents as Strings
-
Chapter 6 Functions
-
Introduction
-
Accessing Function Parameters
-
Setting Default Values for Function Parameters
-
Passing Values by Reference
-
Using Named Parameters
-
Creating Functions That Take a Variable Number of Arguments
-
Returning Values by Reference
-
Returning More Than One Value
-
Skipping Selected Return Values
-
Returning Failure
-
Calling Variable Functions
-
Accessing a Global Variable Inside a Function
-
Creating Dynamic Functions
-
Chapter 7 Classes and Objects
-
Introduction
-
Instantiating Objects
-
Defining Object Constructors
-
Destroying an Object
-
Cloning Objects
-
Assigning Object References
-
Calling Methods on an Object Returned by Another Method
-
Accessing Overridden Methods
-
Using Property Overloading
-
Using Method Polymorphism
-
Finding the Methods and Properties of an Object
-
Adding Properties to a Base Object
-
Creating a Class Dynamically
-
Instantiating an Object Dynamically
-
Chapter 8 Web Basics
-
Introduction
-
Setting Cookies
-
Reading Cookie Values
-
Deleting Cookies
-
Redirecting to a Different Location
-
Using Session Tracking
-
Storing Sessions in a Database
-
Detecting Different Browsers
-
Building a GET Query String
-
Using HTTP Basic Authentication
-
Using Cookie Authentication
-
Flushing Output to the Browser
-
Buffering Output to the Browser
-
Compressing Web Output with gzip
-
Hiding Error Messages from Users
-
Tuning Error Handling
-
Using a Custom Error Handler
-
Logging Errors
-
Eliminating "headers already sent" Errors
-
Logging Debugging Information
-
Reading Environment Variables
-
Setting Environment Variables
-
Reading Configuration Variables
-
Setting Configuration Variables
-
Communicating Within Apache
-
Profiling Code
-
Program: Website Account (De)activator
-
Program: Abusive User Checker
-
Chapter 9 Forms
-
Introduction
-
Processing Form Input
-
Validating Form Input
-
Working with Multipage Forms
-
Redisplaying Forms with Preserved Information and Error Messages
-
Guarding Against Multiple Submission of the Same Form
-
Processing Uploaded Files
-
Securing PHP's Form Processing
-
Escaping Control Characters from User Data
-
Handling Remote Variables with Periods in Their Names
-
Using Form Elements with Multiple Options
-
Creating Dropdown Menus Based on the Current Date
-
Chapter 10 Database Access
-
Introduction
-
Using Text-File Databases
-
Using DBM Databases
-
Connecting to a SQL Database
-
Querying a SQL Database
-
Retrieving Rows Without a Loop
-
Modifying Data in a SQL Database
-
Repeating Queries Efficiently
-
Finding the Number of Rows Returned by a Query
-
Escaping Quotes
-
Logging Debugging Information and Errors
-
Assigning Unique ID Values Automatically
-
Building Queries Programmatically
-
Making Paginated Links for a Series of Records
-
Caching Queries and Results
-
Program: Storing a Threaded Message Board
-
Chapter 11 Web Automation
-
Introduction
-
Fetching a URL with the GET Method
-
Fetching a URL with the POST Method
-
Fetching a URL with Cookies
-
Fetching a URL with Headers
-
Fetching an HTTPS URL
-
Debugging the Raw HTTP Exchange
-
Marking Up a Web Page
-
Extracting Links from an HTML File
-
Converting ASCII to HTML
-
Converting HTML to ASCII
-
Removing HTML and PHP Tags
-
Using Smarty Templates
-
Parsing a Web Server Log File
-
Program: Finding Stale Links
-
Program: Finding Fresh Links
-
Chapter 12 XML
-
Introduction
-
Generating XML Manually
-
Generating XML with the DOM
-
Parsing XML with the DOM
-
Parsing XML with SAX
-
Transforming XML with XSLT
-
Sending XML-RPC Requests
-
Receiving XML-RPC Requests
-
Sending SOAP Requests
-
Receiving SOAP Requests
-
Exchanging Data with WDDX
-
Reading RSS Feeds
-
Chapter 13 Regular Expressions
-
Introduction
-
Switching From ereg to preg
-
Matching Words
-
Finding the nth Occurrence of a Match
-
Choosing Greedy or Nongreedy Matches
-
Matching a Valid Email Address
-
Finding All Lines in a File That Match a Pattern
-
Capturing Text Inside HTML Tags
-
Escaping Special Characters in a Regular Expression
-
Reading Records with a Pattern Separator
-
Chapter 14 Encryption and Security
-
Introduction
-
Keeping Passwords Out of Your Site Files
-
Obscuring Data with Encoding
-
Verifying Data with Hashes
-
Storing Passwords
-
Checking Password Strength
-
Dealing with Lost Passwords
-
Encrypting and Decrypting Data
-
Storing Encrypted Data in a File or Database
-
Sharing Encrypted Data with Another Web Site
-
Detecting SSL
-
Encrypting Email with GPG
-
Chapter 15 Graphics
-
Introduction
-
Drawing Lines, Rectangles, and Polygons
-
Drawing Arcs, Ellipses, and Circles
-
Drawing with Patterned Lines
-
Drawing Text
-
Drawing Centered Text
-
Building Dynamic Images
-
Getting and Setting a Transparent Color
-
Serving Images Securely
-
Program: Generating Bar Charts from Poll Results
-
Chapter 16 Internationalization and Localization
-
Introduction
-
Listing Available Locales
-
Using a Particular Locale
-
Setting the Default Locale
-
Localizing Text Messages
-
Localizing Dates and Times
-
Localizing Currency Values
-
Localizing Images
-
Localizing Included Files
-
Managing Localization Resources
-
Using gettext
-
Reading or Writing Unicode Characters
-
Chapter 17 Internet Services
-
Introduction
-
Sending Mail
-
Sending MIME Mail
-
Reading Mail with IMAP or POP3
-
Posting Messages to Usenet Newsgroups
-
Reading Usenet News Messages
-
Getting and Putting Files with FTP
-
Looking Up Addresses with LDAP
-
Using LDAP for User Authentication
-
Performing DNS Lookups
-
Checking if a Host Is Alive
-
Getting Information About a Domain Name
-
Chapter 18 Files
-
Introduction
-
Creating or Opening a Local File
-
Creating a Temporary File
-
Opening a Remote File
-
Reading from Standard Input
-
Reading a File into a String
-
Counting Lines, Paragraphs, or Records in a File
-
Processing Every Word in a File
-
Reading a Particular Line in a File
-
Processing a File Backward by Line or Paragraph
-
Picking a Random Line from a File
-
Randomizing All Lines in a File
-
Processing Variable Length Text Fields
-
Reading Configuration Files
-
Reading from or Writing to a Specific Location in a File
-
Removing the Last Line of a File
-
Modifying a File in Place Without a Temporary File
-
Flushing Output to a File
-
Writing to Standard Output
-
Writing to Many Filehandles Simultaneously
-
Escaping Shell Metacharacters
-
Passing Input to a Program
-
Reading Standard Output from a Program
-
Reading Standard Error from a Program
-
Locking a File
-
Reading and Writing Compressed Files
-
Program: Unzip
-
Chapter 19 Directories
-
Introduction
-
Getting and Setting File Timestamps
-
Getting File Information
-
Changing File Permissions or Ownership
-
Splitting a Filename into Its Component Parts
-
Deleting a File
-
Copying or Moving a File
-
Processing All Files in a Directory Recursively
-
Getting a List of Filenames Matching a Pattern
-
Processing All Files in a Directory
-
Making New Directories
-
Removing a Directory and Its Contents
-
Program: Web Server Directory Listing
-
Program: Site Search
-
Chapter 20 Client-Side PHP
-
Introduction
-
Parsing Program Arguments
-
Parsing Program Arguments with getopt
-
Reading from the Keyboard
-
Reading Passwords
-
Displaying a GUI Widget in a Window
-
Displaying Multiple GUI Widgets in a Window
-
Responding to User Actions
-
Displaying Menus
-
Program: Command Shell
-
Program: Displaying Weather Conditions
-
Chapter 21 PEAR
-
Introduction
-
Using the PEAR Package Manager
-
Finding PEAR Packages
-
Finding Information About a Package
-
Installing PEAR Packages
-
Installing PECL Packages
-
Upgrading PEAR Packages
-
Uninstalling PEAR Packages
-
Documenting Classes with PHPDoc
-
Colophon
Return to PHP Cookbook