PHP Cookbook


PHP is a simple yet powerful open source scripting language that has become a big player in web development. Over a million web sites, from large corporate sites to small personal sites, are using PHP to serve dynamic web content. PHP's broad feature set, approachable syntax, and support for different operating systems and web servers make it an ideal language for rapid web development. The PHP Cookbook is a collection of problems, solutions, and practical examples for PHP programmers. The book contains a unique ...
See more details below
Available through our Marketplace sellers.
Other sellers (Paperback)
  • All (29) from $1.99   
  • New (4) from $15.96   
  • Used (25) from $1.99   
Sort by
Page 1 of 1
Showing All
Note: Marketplace items are not eligible for any coupons and promotions
Seller since 2008

Feedback rating:



New — never opened or used in original packaging.

Like New — packaging may have been opened. A "Like New" item is suitable to give as a gift.

Very Good — may have minor signs of wear on packaging but item works perfectly and has no damage.

Good — item is in good condition but packaging may have signs of shelf wear/aging or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Acceptable — item is in working order but may show signs of wear such as scratches or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Used — An item that has been opened and may show signs of wear. All specific defects should be noted in the Comments section associated with each item.

Refurbished — A used item that has been renewed or updated and verified to be in proper working condition. Not necessarily completed by the original manufacturer.


Ships from: fallbrook, CA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
Seller since 2009

Feedback rating:


Condition: New
1565926811 *BRAND NEW* Ships Same Day or Next!

Ships from: Springfield, VA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
Seller since 2014

Feedback rating:


Condition: New
Brand new.

Ships from: acton, MA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
Seller since 2014

Feedback rating:


Condition: New
Brand new.

Ships from: acton, MA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
Page 1 of 1
Showing All
Sort by
Sending request ...


PHP is a simple yet powerful open source scripting language that has become a big player in web development. Over a million web sites, from large corporate sites to small personal sites, are using PHP to serve dynamic web content. PHP's broad feature set, approachable syntax, and support for different operating systems and web servers make it an ideal language for rapid web development. The PHP Cookbook is a collection of problems, solutions, and practical examples for PHP programmers. The book contains a unique and extensive collection of best practices for everyday PHP programming dilemmas. For every problem addressed in the book, there's a worked-out solution or "recipe" -- a short, focused piece of code you can insert directly into your application. However, this book offers more than cut-and-paste code. You also get explanations of how and why the code works, so you can learn to adapt the problem-solving techniques to similar situations. The recipes in the PHP Cookbook range from simple tasks, such as sending a database query and fetching URLs, to entire programs that demonstrate complex tasks, such as printing HTML tables and generating bar charts. This book contains an impressive collection of useful code for PHP programmers, from novices to advanced practitioners. Instead of poking around mailing lists, online documentation, and other sources, you can rely on the PHP Cookbook to provide quick solutions to common problems, so you can spend your time on those out-of-the-ordinary problems specific to your application.

When it comes to creating dynamic web sites, the open source PHP language is used on more 19 million Web sites today. With this resource, readers can learn how to build dynamic Web applications that work on any Web browser.

Read More Show Less

Editorial Reviews

From Barnes & Noble
The Barnes & Noble Review
Right now, hundreds of programmers are using PHP to solve virtually the same problems. Some are writing great code. Some are writing mediocre code. Some are searching the Web for code to steal. Now they’ve all got a single source for high-quality PHP code: The PHP Cookbook.

There are 250 “recipes” here -- but this is better than mere “cut and paste.” The authors explain exactly how and why the code works, so you can adapt it to your own situation without losing its elegance or robustness.

The solutions they provide cover the waterfront -- from simple tasks that only require a minor php.ini settings adjustment (like sending compressed web output to browsers that support it) to entire programs for handling complex challenges (like printing arrays in horizontally columned HTML tables and building bar charts).

You name it, it’s here. Session tracking. Authentication. Validating dates (and accounting for Daylight Ssavings Time). Secure forms processing. Connecting to and querying SQL databases. Fetching URLs (with GET, POST, and cookies). Generating XML, either manually or with DOM. Encrypting and decrypting data. Sending and reading email. Working with PEAR packages. Use these solutions -- and spend your precious time doing something original. Bill Camarda

Bill Camarda is a consultant, writer, and web/multimedia content developer. His 15 books include Special Edition Using Word 2000 and Upgrading & Fixing Networks For Dummies®, Second Edition.

Read More Show Less

Product Details

  • ISBN-13: 9781565926813
  • Publisher: O'Reilly Media, Incorporated
  • Publication date: 10/17/2002
  • Pages: 640
  • Product dimensions: 7.08 (w) x 9.16 (h) x 1.12 (d)

Meet the Author

David Sklar is a Distinguished Engineer at Ning, part of Glam Media. Inaddition to PHP Cookbook, he is the author of Learning PHP 5 (O'Reilly), and Essential PHP Tools (Apress), and a scintillating blog: David lives in New York City and has adegree in Computer Science from Yale University.

Adam Trachtenberg is the Director of Platform and Services for eBay and is the author of two O'Reilly books, Upgrading to PHP 5 and PHP Cookbook.

Adam has an MBA from Columbia Business School. While there, he focused on general management and operations, with an emphasis on the field of technology. Adam also has a BA from Columbia University. As an undergraduate he majored in mathematics, and his other studies included computer science and Chinese.

Read More Show Less

Table of Contents

Who This Book Is For;
What Is in This Book;
Other Resources;
Conventions Used in This Book;
Comments and Questions;
Chapter 1: Strings;
1.1 Introduction;
1.2 Accessing Substrings;
1.3 Replacing Substrings;
1.4 Processing a String One Character at a Time;
1.5 Reversing a String by Word or Character;
1.6 Expanding and Compressing Tabs;
1.7 Controlling Case;
1.8 Interpolating Functions and Expressions Within Strings;
1.9 Trimming Blanks from a String;
1.10 Parsing Comma-Separated Data;
1.11 Parsing Fixed-Width Delimited Data;
1.12 Taking Strings Apart;
1.13 Wrapping Text at a Certain Line Length;
1.14 Storing Binary Data in Strings;
Chapter 2: Numbers;
2.1 Introduction;
2.2 Checking Whether a String Contains a Valid Number;
2.3 Comparing Floating-Point Numbers;
2.4 Rounding Floating-Point Numbers;
2.5 Operating on a Series of Integers;
2.6 Generating Random Numbers Within a Range;
2.7 Generating Biased Random Numbers;
2.8 Taking Logarithms;
2.9 Calculating Exponents;
2.10 Formatting Numbers;
2.11 Printing Correct Plurals;
2.12 Calculating Trigonometric Functions;
2.13 Doing Trigonometry in Degrees, not Radians;
2.14 Handling Very Large or Very Small Numbers;
2.15 Converting Between Bases;
2.16 Calculating Using Numbers in Bases Other Than Decimal;
Chapter 3: Dates and Times;
3.1 Introduction;
3.2 Finding the Current Date and Time;
3.3 Converting Time and Date Parts to an Epoch Timestamp;
3.4 Converting an Epoch Timestamp to Time and Date Parts;
3.5 Printing a Date or Time in a Specified Format;
3.6 Finding the Difference of Two Dates;
3.7 Finding the Difference of Two Dates with Julian Days;
3.8 Finding the Day in a Week, Month, Year, or the Week Number in a Year;
3.9 Validating a Date;
3.10 Parsing Dates and Times from Strings;
3.11 Adding to or Subtracting from a Date;
3.12 Calculating Time with Time Zones;
3.13 Accounting for Daylight Saving Time;
3.14 Generating a High-Precision Time;
3.15 Generating Time Ranges;
3.16 Using Non-Gregorian Calendars;
3.17 Program: Calendar;
Chapter 4: Arrays;
4.1 Introduction;
4.2 Specifying an Array Not Beginning at Element 0;
4.3 Storing Multiple Elements per Key in an Array;
4.4 Initializing an Array to a Range of Integers;
4.5 Iterating Through an Array;
4.6 Deleting Elements from an Array;
4.7 Changing Array Size;
4.8 Appending One Array to Another;
4.9 Turning an Array into a String;
4.10 Printing an Array with Commas;
4.11 Checking if a Key Is in an Array;
4.12 Checking if an Element Is in an Array;
4.13 Finding the Position of an Element in an Array;
4.14 Finding Elements That Pass a Certain Test;
4.15 Finding the Largest or Smallest Valued Element in an Array;
4.16 Reversing an Array;
4.17 Sorting an Array;
4.18 Sorting an Array by a Computable Field;
4.19 Sorting Multiple Arrays;
4.20 Sorting an Array Using a Method Instead of a Function;
4.21 Randomizing an Array;
4.22 Shuffling a Deck of Cards;
4.23 Removing Duplicate Elements from an Array;
4.24 Finding the Union, Intersection, or Difference of Two Arrays;
4.25 Finding All Element Combinations of an Array;
4.26 Finding All Permutations of an Array;
4.27 Program: Printing an Array in a Horizontally Columned HTML Table;
Chapter 5: Variables;
5.1 Introduction;
5.2 Avoiding == Versus = Confusion;
5.3 Establishing a Default Value;
5.4 Exchanging Values Without Using Temporary Variables;
5.5 Creating a Dynamic Variable Name;
5.6 Using Static Variables;
5.7 Sharing Variables Between Processes;
5.8 Encapsulating Complex Data Types as a String;
5.9 Dumping Variable Contents as Strings;
Chapter 6: Functions;
6.1 Introduction;
6.2 Accessing Function Parameters;
6.3 Setting Default Values for Function Parameters;
6.4 Passing Values by Reference;
6.5 Using Named Parameters;
6.6 Creating Functions That Take a Variable Number of Arguments;
6.7 Returning Values by Reference;
6.8 Returning More Than One Value;
6.9 Skipping Selected Return Values;
6.10 Returning Failure;
6.11 Calling Variable Functions;
6.12 Accessing a Global Variable Inside a Function;
6.13 Creating Dynamic Functions;
Chapter 7: Classes and Objects;
7.1 Introduction;
7.2 Instantiating Objects;
7.3 Defining Object Constructors;
7.4 Destroying an Object;
7.5 Cloning Objects;
7.6 Assigning Object References;
7.7 Calling Methods on an Object Returned by Another Method;
7.8 Accessing Overridden Methods;
7.9 Using Property Overloading;
7.10 Using Method Polymorphism;
7.11 Finding the Methods and Properties of an Object;
7.12 Adding Properties to a Base Object;
7.13 Creating a Class Dynamically;
7.14 Instantiating an Object Dynamically;
Chapter 8: Web Basics;
8.1 Introduction;
8.2 Setting Cookies;
8.3 Reading Cookie Values;
8.4 Deleting Cookies;
8.5 Redirecting to a Different Location;
8.6 Using Session Tracking;
8.7 Storing Sessions in a Database;
8.8 Detecting Different Browsers;
8.9 Building a GET Query String;
8.10 Using HTTP Basic Authentication;
8.11 Using Cookie Authentication;
8.12 Flushing Output to the Browser;
8.13 Buffering Output to the Browser;
8.14 Compressing Web Output with gzip;
8.15 Hiding Error Messages from Users;
8.16 Tuning Error Handling;
8.17 Using a Custom Error Handler;
8.18 Logging Errors;
8.19 Eliminating “headers already sent” Errors;
8.20 Logging Debugging Information;
8.21 Reading Environment Variables;
8.22 Setting Environment Variables;
8.23 Reading Configuration Variables;
8.24 Setting Configuration Variables;
8.25 Communicating Within Apache;
8.26 Profiling Code;
8.27 Program: Website Account (De)activator;
8.28 Program: Abusive User Checker;
Chapter 9: Forms;
9.1 Introduction;
9.2 Processing Form Input;
9.3 Validating Form Input;
9.4 Working with Multipage Forms;
9.5 Redisplaying Forms with Preserved Information and Error Messages;
9.6 Guarding Against Multiple Submission of the Same Form;
9.7 Processing Uploaded Files;
9.8 Securing PHP’s Form Processing;
9.9 Escaping Control Characters from User Data;
9.10 Handling Remote Variables with Periods in Their Names;
9.11 Using Form Elements with Multiple Options;
9.12 Creating Dropdown Menus Based on the Current Date;
Chapter 10: Database Access;
10.1 Introduction;
10.2 Using Text-File Databases;
10.3 Using DBM Databases;
10.4 Connecting to a SQL Database;
10.5 Querying a SQL Database;
10.6 Retrieving Rows Without a Loop;
10.7 Modifying Data in a SQL Database;
10.8 Repeating Queries Efficiently;
10.9 Finding the Number of Rows Returned by a Query;
10.10 Escaping Quotes;
10.11 Logging Debugging Information and Errors;
10.12 Assigning Unique ID Values Automatically;
10.13 Building Queries Programmatically;
10.14 Making Paginated Links for a Series of Records;
10.15 Caching Queries and Results;
10.16 Program: Storing a Threaded Message Board;
Chapter 11: Web Automation;
11.1 Introduction;
11.2 Fetching a URL with the GET Method;
11.3 Fetching a URL with the POST Method;
11.4 Fetching a URL with Cookies;
11.5 Fetching a URL with Headers;
11.6 Fetching an HTTPS URL;
11.7 Debugging the Raw HTTP Exchange;
11.8 Marking Up a Web Page;
11.9 Extracting Links from an HTML File;
11.10 Converting ASCII to HTML;
11.11 Converting HTML to ASCII;
11.12 Removing HTML and PHP Tags;
11.13 Using Smarty Templates;
11.14 Parsing a Web Server Log File;
11.15 Program: Finding Stale Links;
11.16 Program: Finding Fresh Links;
Chapter 12: XML;
12.1 Introduction;
12.2 Generating XML Manually;
12.3 Generating XML with the DOM;
12.4 Parsing XML with the DOM;
12.5 Parsing XML with SAX;
12.6 Transforming XML with XSLT;
12.7 Sending XML-RPC Requests;
12.8 Receiving XML-RPC Requests;
12.9 Sending SOAP Requests;
12.10 Receiving SOAP Requests;
12.11 Exchanging Data with WDDX;
12.12 Reading RSS Feeds;
Chapter 13: Regular Expressions;
13.1 Introduction;
13.2 Switching From ereg to preg;
13.3 Matching Words;
13.4 Finding the nth Occurrence of a Match;
13.5 Choosing Greedy or Nongreedy Matches;
13.6 Matching a Valid Email Address;
13.7 Finding All Lines in a File That Match a Pattern;
13.8 Capturing Text Inside HTML Tags;
13.9 Escaping Special Characters in a Regular Expression;
13.10 Reading Records with a Pattern Separator;
Chapter 14: Encryption and Security;
14.1 Introduction;
14.2 Keeping Passwords Out of Your Site Files;
14.3 Obscuring Data with Encoding;
14.4 Verifying Data with Hashes;
14.5 Storing Passwords;
14.6 Checking Password Strength;
14.7 Dealing with Lost Passwords;
14.8 Encrypting and Decrypting Data;
14.9 Storing Encrypted Data in a File or Database;
14.10 Sharing Encrypted Data with Another Web Site;
14.11 Detecting SSL;
14.12 Encrypting Email with GPG;
Chapter 15: Graphics;
15.1 Introduction;
15.2 Drawing Lines, Rectangles, and Polygons;
15.3 Drawing Arcs, Ellipses, and Circles;
15.4 Drawing with Patterned Lines;
15.5 Drawing Text;
15.6 Drawing Centered Text;
15.7 Building Dynamic Images;
15.8 Getting and Setting a Transparent Color;
15.9 Serving Images Securely;
15.10 Program: Generating Bar Charts from Poll Results;
Chapter 16: Internationalization and Localization;
16.1 Introduction;
16.2 Listing Available Locales;
16.3 Using a Particular Locale;
16.4 Setting the Default Locale;
16.5 Localizing Text Messages;
16.6 Localizing Dates and Times;
16.7 Localizing Currency Values;
16.8 Localizing Images;
16.9 Localizing Included Files;
16.10 Managing Localization Resources;
16.11 Using gettext;
16.12 Reading or Writing Unicode Characters;
Chapter 17: Internet Services;
17.1 Introduction;
17.2 Sending Mail;
17.3 Sending MIME Mail;
17.4 Reading Mail with IMAP or POP3;
17.5 Posting Messages to Usenet Newsgroups;
17.6 Reading Usenet News Messages;
17.7 Getting and Putting Files with FTP;
17.8 Looking Up Addresses with LDAP;
17.9 Using LDAP for User Authentication;
17.10 Performing DNS Lookups;
17.11 Checking if a Host Is Alive;
17.12 Getting Information About a Domain Name;
Chapter 18: Files;
18.1 Introduction;
18.2 Creating or Opening a Local File;
18.3 Creating a Temporary File;
18.4 Opening a Remote File;
18.5 Reading from Standard Input;
18.6 Reading a File into a String;
18.7 Counting Lines, Paragraphs, or Records in a File;
18.8 Processing Every Word in a File;
18.9 Reading a Particular Line in a File;
18.10 Processing a File Backward by Line or Paragraph;
18.11 Picking a Random Line from a File;
18.12 Randomizing All Lines in a File;
18.13 Processing Variable Length Text Fields;
18.14 Reading Configuration Files;
18.15 Reading from or Writing to a Specific Location in a File;
18.16 Removing the Last Line of a File;
18.17 Modifying a File in Place Without a Temporary File;
18.18 Flushing Output to a File;
18.19 Writing to Standard Output;
18.20 Writing to Many Filehandles Simultaneously;
18.21 Escaping Shell Metacharacters;
18.22 Passing Input to a Program;
18.23 Reading Standard Output from a Program;
18.24 Reading Standard Error from a Program;
18.25 Locking a File;
18.26 Reading and Writing Compressed Files;
18.27 Program: Unzip;
Chapter 19: Directories;
19.1 Introduction;
19.2 Getting and Setting File Timestamps;
19.3 Getting File Information;
19.4 Changing File Permissions or Ownership;
19.5 Splitting a Filename into Its Component Parts;
19.6 Deleting a File;
19.7 Copying or Moving a File;
19.8 Processing All Files in a Directory Recursively;
19.9 Getting a List of Filenames Matching a Pattern;
19.10 Processing All Files in a Directory;
19.11 Making New Directories;
19.12 Removing a Directory and Its Contents;
19.13 Program: Web Server Directory Listing;
19.14 Program: Site Search;
Chapter 20: Client-Side PHP;
20.1 Introduction;
20.2 Parsing Program Arguments;
20.3 Parsing Program Arguments with getopt;
20.4 Reading from the Keyboard;
20.5 Reading Passwords;
20.6 Displaying a GUI Widget in a Window;
20.7 Displaying Multiple GUI Widgets in a Window;
20.8 Responding to User Actions;
20.9 Displaying Menus;
20.10 Program: Command Shell;
20.11 Program: Displaying Weather Conditions;
Chapter 21: PEAR;
21.1 Introduction;
21.2 Using the PEAR Package Manager;
21.3 Finding PEAR Packages;
21.4 Finding Information About a Package;
21.5 Installing PEAR Packages;
21.6 Installing PECL Packages;
21.7 Upgrading PEAR Packages;
21.8 Uninstalling PEAR Packages;
21.9 Documenting Classes with PHPDoc;

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)