Book Review


PHP Cookbook

By: David Sklar, Adam Trachtenberg
Publishers: O'Reilly & Associates
Released: November, 2002
Sales Rank: 5,350+
Pages: 632
Price: $39.95 US, $61.95 CA, £28.50 UK
Review
Table of Contents
Sample Chapter


Review by Stuart Cochrane

If this book was a painting it would certainly be a Van Gogh, you can just tell that an extreme amount of hard work has went into the production of this masterpiece (let's hope their bodies remain intact though :). Its a delight to have such a refreshingly thorough and easy to read PHP book to hand, and unless you wrote the book I'm sure you will learn a thing or two.

Assuming you have the basics of programming with PHP or some other similar scripting language, I'm sure you will find this book an easy read with a perfect depth of information to solve you everyday (and some more unusual) programming problems. Anyone serious about learning or improving their PHP knowledge will only gain from this book.

The first 7 chapters give you a in-depth look at the PHP language basics, looking at the how the syntax hangs together it covers- Strings, Numbers, Dates and Times, Arrays, Variables, Functions, Classes and Objects. Then we move on to some basic programming examples including Cookies, Sessions, Form Processing and Databases Access. Later on some more advanced topics are covered including XML, Encryption and Security, Graphics and Client Side PHP with PHP-GTK.

I have to say that I started reading this book a the right time. I was experiencing problems with the recent 'Daylight Saving Time' change, and could not find an answer anywhere (even after spending hours on php.net and google.com). I decided to have a look on my brand new book (which had arrived that day) and was very surprised to find the exact solution sitting right there (recipe 3.12). This recipe saved the day :-), thank you.

One thing to note - you will noticed the Authors fondness for PEAR, many recipes use PEAR functions and classes to solve problems. Some people will like this, some will not, but my opinion is 'why reinvent the wheel!' Almost all functions used include the URL to more information, which makes it the solutions more complete.

Overall I have to say its the best PHP (and programming/scripting) book I have ever read and, look forward, excitingly, to using my new found knowledge gained from it. I will be keeping my eyes and ears wide open for other books by these Authors and really hope you gain from it as much as I have.


Content: 10
Completeness: 9
Quality: 10
Price: 9
   
Overall: 9

 

top of page

 


Table of Contents

Preface

1. Strings
1.1 Accessing Substrings
1.2 Replacing Substrings
1.3 Processing a String One Character at a Time
1.4 Reversing a String by Word or Character
1.5 Expanding and Compressing Tabs
1.6 Controlling Case
1.7 Interpolating Functions and Expressions Within Strings
1.8 Trimming Blanks from a String
1.9 Parsing Comma-Separated Data
1.10 Parsing Fixed-Width Delimited Data
1.11 Taking Strings Apart
1.12 Wrapping Text at a Certain Line Length
1.13 Storing Binary Data in Strings

2. Numbers
2.1 Checking Whether a String Contains a Valid Number
2.2 Comparing Floating-Point Numbers
2.3 Rounding Floating-Point Numbers
2.4 Operating on a Series of Integers
2.5 Generating Random Numbers Within a Range
2.6 Generating Biased Random Numbers
2.7 Taking Logarithms
2.8 Calculating Exponents
2.9 Formatting Numbers
2.10 Printing Correct Plurals
2.11 Calculating Trigonometric Functions
2.12 Doing Trigonometry in Degrees, not Radians
2.13 Handling Very Large or Very Small Numbers
2.14 Converting Between Bases
2.15 Calculating Using Numbers in Bases Other Than Decimal

3. Dates and Times
3.1 Finding the Current Date and Time
3.2 Converting Time and Date Parts to an Epoch Timestamp
3.3 Converting an Epoch Timestamp to Time and Date Parts
3.4 Printing a Date or Time in a Specified Format
3.5 Finding the Difference of Two Dates
3.6 Finding the Difference of Two Dates with Julian Days
3.7 Finding the Day in a Week, Month, Year, or the Week Number in a Year
3.8 Validating a Date
3.9 Parsing Dates and Times from Strings
3.10 Adding to or Subtracting from a Date
3.11 Calculating Time with Time Zones
3.12 Accounting for Daylight Saving Time
3.13 Generating a High-Precision Time
3.14 Generating Time Ranges
3.15 Using Non-Gregorian Calendars
3.16 Program: Calendar

4. Arrays
4.1 Specifying an Array Not Beginning at Element 0
4.2 Storing Multiple Elements per Key in an Array
4.3 Initializing an Array to a Range of Integers
4.4 Iterating Through an Array
4.5 Deleting Elements from an Array
4.6 Changing Array Size
4.7 Appending One Array to Another
4.8 Turning an Array into a String
4.9 Printing an Array with Commas
4.10 Checking if a Key Is in an Array
4.11 Checking if an Element Is in an Array
4.12 Finding the Position of an Element in an Array
4.13 Finding Elements That Pass a Certain Test
4.14 Finding the Largest or Smallest Valued Element in an Array
4.15 Reversing an Array
4.16 Sorting an Array
4.17 Sorting an Array by a Computable Field
4.18 Sorting Multiple Arrays
4.19 Sorting an Array Using a Method Instead of a Function
4.20 Randomizing an Array
4.21 Shuffling a Deck of Cards
4.22 Removing Duplicate Elements from an Array
4.23 Finding the Union, Intersection, or Difference of Two Arrays
4.24 Finding All Element Combinations of an Array
4.25 Finding All Permutations of an Array
4.26 Program: Printing an Array in a Horizontally Columned HTML Table

5. Variables
5.1 Avoiding == Versus = Confusion
5.2 Establishing a Default Value
5.3 Exchanging Values Without Using Temporary Variables
5.4 Creating a Dynamic Variable Name
5.5 Using Static Variables
5.6 Sharing Variables Between Processes
5.7 Encapsulating Complex Data Types as a String
5.8 Dumping Variable Contents as Strings

6. Functions
6.1 Accessing Function Parameters
6.2 Setting Default Values for Function Parameters
6.3 Passing Values by Reference
6.4 Using Named Parameters
6.5 Creating Functions That Take a Variable Number of Arguments
6.6 Returning Values by Reference
6.7 Returning More Than One Value
6.8 Skipping Selected Return Values
6.9 Returning Failure
6.10 Calling Variable Functions
6.11 Accessing a Global Variable Inside a Function
6.12 Creating Dynamic Functions

7. Classes and Objects
7.1 Instantiating Objects
7.2 Defining Object Constructors
7.3 Destroying an Object
7.4 Cloning Objects
7.5 Assigning Object References
7.6 Calling Methods on an Object Returned by Another Method
7.7 Accessing Overridden Methods
7.8 Using Property Overloading
7.9 Using Method Polymorphism
7.10 Finding the Methods and Properties of an Object
7.11 Adding Properties to a Base Object
7.12 Creating a Class Dynamically
7.13 Instantiating an Object Dynamically

8. Web Basics
8.1 Setting Cookies
8.2 Reading Cookie Values
8.3 Deleting Cookies
8.4 Redirecting to a Different Location
8.5 Using Session Tracking
8.6 Storing Sessions in a Database
8.7 Detecting Different Browsers
8.8 Building a GET Query String
8.9 Using HTTP Basic Authentication
8.10 Using Cookie Authentication
8.11 Flushing Output to the Browser
8.12 Buffering Output to the Browser
8.13 Compressing Web Output with gzip
8.14 Hiding Error Messages from Users
8.15 Tuning Error Handling
8.16 Using a Custom Error Handler
8.17 Logging Errors
8.18 Eliminating "headers already sent" Errors
8.19 Logging Debugging Information
8.20 Reading Environment Variables
8.21 Setting Environment Variables
8.22 Reading Configuration Variables
8.23 Setting Configuration Variables
8.24 Communicating Within Apache
8.25 Profiling Code
8.26 Program: Website Account (De)activator
8.27 Program: Abusive User Checker

9. Forms
9.1 Processing Form Input
9.2 Validating Form Input
9.3 Working with Multipage Forms
9.4 Redisplaying Forms with Preserved Information and Error Messages
9.5 Guarding Against Multiple Submission of the Same Form
9.6 Processing Uploaded Files
9.7 Securing PHP's Form Processing
9.8 Escaping Control Characters from User Data
9.9 Handling Remote Variables with Periods in Their Names
9.10 Using Form Elements with Multiple Options
9.11 Creating Dropdown Menus Based on the Current Date

10. Database Access
10.1 Using Text-File Databases
10.2 Using DBM Databases
10.3 Connecting to a SQL Database
10.4 Querying a SQL Database
10.5 Retrieving Rows Without a Loop
10.6 Modifying Data in a SQL Database
10.7 Repeating Queries Efficiently
10.8 Finding the Number of Rows Returned by a Query
10.9 Escaping Quotes
10.10 Logging Debugging Information and Errors
10.11 Assigning Unique ID Values Automatically
10.12 Building Queries Programmatically
10.13 Making Paginated Links for a Series of Records
10.14 Caching Queries and Results
10.15 Program: Storing a Threaded Message Board

11. Web Automation
11.1 Fetching a URL with the GET Method
11.2 Fetching a URL with the POST Method
11.3 Fetching a URL with Cookies
11.4 Fetching a URL with Headers
11.5 Fetching an HTTPS URL
11.6 Debugging the Raw HTTP Exchange
11.7 Marking Up a Web Page
11.8 Extracting Links from an HTML File
11.9 Converting ASCII to HTML
11.10 Converting HTML to ASCII
11.11 Removing HTML and PHP Tags
11.12 Using Smarty Templates
11.13 Parsing a Web Server Log File
11.14 Program: Finding Stale Links
11.15 Program: Finding Fresh Links

12. XML
12.1 Generating XML Manually
12.2 Generating XML with the DOM
12.3 Parsing XML with the DOM
12.4 Parsing XML with SAX
12.5 Transforming XML with XSLT
12.6 Sending XML-RPC Requests
12.7 Receiving XML-RPC Requests
12.8 Sending SOAP Requests
12.9 Receiving SOAP Requests
12.10 Exchanging Data with WDDX
12.11 Reading RSS Feeds

13. Regular Expressions
13.1 Switching From ereg to preg
13.2 Matching Words
13.3 Finding the nth Occurrence of a Match
13.4 Choosing Greedy or Nongreedy Matches
13.5 Matching a Valid Email Address
13.6 Finding All Lines in a File That Match a Pattern
13.7 Capturing Text Inside HTML Tags
13.8 Escaping Special Characters in a Regular Expression
13.9 Reading Records with a Pattern Separator

14. Encryption and Security
14.1 Keeping Passwords Out of Your Site Files
14.2 Obscuring Data with Encoding
14.3 Verifying Data with Hashes
14.4 Storing Passwords
14.5 Checking Password Strength
14.6 Dealing with Lost Passwords
14.7 Encrypting and Decrypting Data
14.8 Storing Encrypted Data in a File or Database
14.9 Sharing Encrypted Data with Another Web Site
14.10 Detecting SSL
14.11 Encrypting Email with GPG

15. Graphics
15.1 Drawing Lines, Rectangles, and Polygons
15.2 Drawing Arcs, Ellipses, and Circles
15.3 Drawing with Patterned Lines
15.4 Drawing Text
15.5 Drawing Centered Text
15.6 Building Dynamic Images
15.7 Getting and Setting a Transparent Color
15.8 Serving Images Securely
15.9 Program: Generating Bar Charts from Poll Results

16. Internationalization and Localization
16.1 Listing Available Locales
16.2 Using a Particular Locale
16.3 Setting the Default Locale
16.4 Localizing Text Messages
16.5 Localizing Dates and Times
16.6 Localizing Currency Values
16.7 Localizing Images
16.8 Localizing Included Files
16.9 Managing Localization Resources
16.10 Using gettext
16.11 Reading or Writing Unicode Characters

17. Internet Services
17.1 Sending Mail
17.2 Sending MIME Mail
17.3 Reading Mail with IMAP or POP3
17.4 Posting Messages to Usenet Newsgroups
17.5 Reading Usenet News Messages
17.6 Getting and Putting Files with FTP
17.7 Looking Up Addresses with LDAP
17.8 Using LDAP for User Authentication
17.9 Performing DNS Lookups
17.10 Checking if a Host Is Alive
17.11 Getting Information About a Domain Name

18. Files
18.1 Creating or Opening a Local File
18.2 Creating a Temporary File
18.3 Opening a Remote File
18.4 Reading from Standard Input
18.5 Reading a File into a String
18.6 Counting Lines, Paragraphs, or Records in a File
18.7 Processing Every Word in a File
18.8 Reading a Particular Line in a File
18.9 Processing a File Backward by Line or Paragraph
18.10 Picking a Random Line from a File
18.11 Randomizing All Lines in a File
18.12 Processing Variable Length Text Fields
18.13 Reading Configuration Files
18.14 Reading from or Writing to a Specific Location in a File
18.15 Removing the Last Line of a File
18.16 Modifying a File in Place Without a Temporary File
18.17 Flushing Output to a File
18.18 Writing to Standard Output
18.19 Writing to Many Filehandles Simultaneously
18.20 Escaping Shell Metacharacters
18.21 Passing Input to a Program
18.22 Reading Standard Output from a Program
18.23 Reading Standard Error from a Program
18.24 Locking a File
18.25 Reading and Writing Compressed Files
18.26 Program: Unzip

19. Directories
19.1 Getting and Setting File Timestamps
19.2 Getting File Information
19.3 Changing File Permissions or Ownership
19.4 Splitting a Filename into Its Component Parts
19.5 Deleting a File
19.6 Copying or Moving a File
19.7 Processing All Files in a Directory
19.8 Getting a List of Filenames Matching a Pattern
19.9 Processing All Files in a Directory
19.10 Making New Directories
19.11 Removing a Directory and Its Contents
19.12 Program: Web Server Directory Listing
19.13 Program: Site Search

20. Client-Side PHP
20.1 Parsing Program Arguments
20.2 Parsing Program Arguments with getopt
20.3 Reading from the Keyboard
20.4 Reading Passwords
20.5 Displaying a GUI Widget in a Window
20.6 Displaying Multiple GUI Widgets in a Window
20.7 Responding to User Actions
20.8 Displaying Menus
20.9 Program: Command Shell
20.10 Program: Displaying Weather Conditions

21. PEAR
21.1 Using the PEAR Package Manager
21.2 Finding PEAR Packages
21.3 Finding Information About a Package
21.4 Installing PEAR Packages
21.5 Installing PECL Packages
21.6 Upgrading PEAR Packages
21.7 Uninstalling PEAR Packages
21.8 Documenting Classes with PHPDoc

Index

top of page


 

Sample Chapter

Chapter 8: Web Basics (PDF Format)

top of page


 










© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.