Table of Contents
This book is organized as both a tutorial and a reference guide, so you can read it any way you like.
- If you're not very experienced with PHP, you might find it easier to read the problems and their solutions sequentially, so that you learn basic techniques in a structured manner. This approach is recommended for new users.
- If you've already used PHP, or if you're experienced in another programming language and are switching to PHP, you might prefer to use this book as a desktop reference, flipping it open on an as-needed basis to read about specific problems and their solutions (the extensive index at the back of this book is designed specifically for this sort of quick lookup).
Here's a quick preview of what each chapter in PHP Programming Solutions contains:
Chapter 1, Working With Strings discusses common problems when working with strings in PHP. Some of the problems discussed include removing unnecessary whitespace, finding and replacing string patterns, counting and extracting string segments, identifying duplicate words, encrypting text and generating string passwords.
Chapter 2, Working With Numbers discusses number manipulation in PHP. Some of the problems discussed include converting number bases; calculating trigonometric values; working with complex numbers and fractions; generating prime numbers; and translating numbers into words in different languages.
Chapter 3, Working With Dates and Times discusses common issues when working with temporal values in PHP. Some of the problems discussed include converting between time zones; calculating the number of days in a month or year; performing date arithmetic; and working with arbitrarily large date values.
Chapter 4, Working With Arrays discusses PHP arrays. Listings include recursively traversing and searching a series of nested arrays, sorting arrays by more than one key, filtering array elements by user-defined criteria, and swapping array keys and values.
Chapter 5, Working With Functions and Classes discusses problems encountered when defining and using functions and classes in PHP. Some of the problems solved include using variable-length argument lists and default arguments; checking class ancestry; overloading class methods; cloning and comparing objects; using abstract classes; and adjusting class member visibility.
Chapter 6, Working With Files and Directories is all about PHP's interaction with the file system. Solutions are included for tasks like searching and replacing patterns within files; comparing file contents; extracting specific lines or bytes from files; recursively processing directories; and converting files between UNIX and MS-DOS formats.
Chapter 7, Working With HTML and Web Pages discusses common tasks related to using PHP in a Web application. It includes listings for finding and turning text URLs into HTML hyperlinks; generating DHTML menu trees from a database; visually displaying the progress of server tasks; and caching and paginating content.
Chapter 8, Working With Forms, Sessions and Cookies discusses common problems of input validation, security and data persistence. Listings are included for storing and retrieving session variables; authenticating users and protecting pages from unauthorized access; building a session-based shopping cart; and creating persistent objects.
Chapter 9, Working With Databases discusses solutions for common problems involving PHP and databases. It includes listings for retrieving a subset of an SQL result set; writing portable database code; performing transactions; protecting special characters in query strings; and storing binary data in a table.
Chapter 10, Working With XML discusses common problems related to using PHP with XML. It includes listings for processing node and attribute values; validating XML against DTDs or Schemas; transforming XML with XSLT style sheets; parsing RSS feeds; and interfacing with SOAP services.
Chapter 11, Working With Different File Formats and Network Protocols is all about interfacing the language with as many servers, protocols and formats as possible. It includes listings for connecting to FTP servers; reading mail in POP3 mailboxes; querying DNS and WHOIS servers; extracting thumbnails from digital JPEGs; dynamically generating PDF files; and creating MIME-compliant email messages.
Chapter 12, Working With Exceptions, And Other Miscellanea discusses common problems related to exception handling and error processing. It also includes solutions for profiling and benchmarking your PHP scripts; executing external programs from within PHP; altering the PHP configuration at run-time; creating compiled PHP bytecode; and localizing PHP applications.