Book description
What you hold in your hands is the answer to all your PHP 5 needs. We have written PHP 5 Recipes with a number of purposes in mind.
First, this book is a source of instant solutions, including countless pieces of useful code that you can just copy and paste into your own applications, giving you answers fast and saving you hours of coding time.
Second, this book is a useful reference to the most important aspects of the PHP 5 language, including the vital functions you know and love from previous versions of PHP, as well as the functions introduced in PHP 5.
Finally, this book explains the PHP 5 functionality in detail, including the vastly improved object-oriented capabilities and the new MySQLi database extension.
We are confident PHP 5 Recipes will be a useful and welcome companion throughout your PHP journey, keeping you on the cutting edge of PHP development, ahead of the competition, and giving you all the answers you need, when you need them.
Table of contents
- Title Page
- Contents at a Glance
- Contents
- About the Authors
- About the Technical Reviewer
- Introduction
-
CHAPTER 1: Overview of PHP Data Types and Concepts
- 1-1. Variables
- 1-2. Numbers
- 1-3. Arrays
- 1-4. Strings
- 1-5. Regular Expressions
- 1-6. Functions
- 1-7. Project: Finding the Data Type of a Value
- 1-8. Project: Discovering What Variables, Constants, Functions, Classes, and Interfaces Are Available
- 1-9. Getting Information About the Current Script
- Summary
- Looking Ahead
-
CHAPTER 2: Overview of Classes, Objects, and Interfaces
- Understanding Basic Concepts
- 2-1. Creating Instances Using Constructors
- 2-2. Using Default Constructors
- 2-3. Setting Object Properties
- 2-4. Controlling Access to Class Members
- 2-5. Using Static Members and the self Keyword
- 2-6. Using Class Constants
- 2-7. Extending Classes
- 2-8. Using Abstract Classes and Methods
- 2-9. Using Interfaces
- 2-10. Using Class Destructors
- 2-11. Using Exceptions
- Getting Information About Classes and Objects
- Using Class and Object Functions
- 2-12. Checking for the Existence of Classes and Interfaces Using class_exists() and interface_exists()
- 2-13. Listing Methods and Interfaces Using get_class_methods()
- 2-14. Obtaining Variable Names
- 2-15. Determining Whether an Object Is an Instance of a Particular Class
- 2-16. Listing Currently Loaded Interfaces and Classes
- Using the Class Reflection API
- 2-17. Obtaining a Dump of the Reflection API
- 2-18. Performing Dynamic Class Instantiation
- 2-19. Using the Reflection API to Deconstruct the Shape Class
- Summary
- Looking Ahead
- CHAPTER 3: Performing Math Operations
-
CHAPTER 4: Working with Arrays
- 4-1. Creating Arrays
- 4-2. Accessing Array Elements
- 4-3. Creating Multidimensional Arrays
- 4-4. Using Array Keys
- 4-5. Initializing an Array As a Range or Sequence of Values
- Outputting Arrays
- 4-6. Outputting an Array As a String
- 4-7. Outputting Using array_values() and array_keys() for Backward Compatibility
- 4-8. Outputting an Array As a Tree
- Adding New Elements to Arrays
- 4-9. Adding an Element to the End of an Array
- 4-10. Appending One Array to Another
- 4-11. Comparing Arrays
- 4-12. Adding an Element to the Beginning of an Array
- 4-13. Inserting New Values at an Arbitrary Point in an Indexed Array
- Getting and Setting the Size of an Array
- 4-14. Counting Array Elements
- 4-15. Setting an Array's Size
- Traversing Arrays
- 4-16. Looping Through an Associative Array Using foreach
- 4-17. Looping Through a Compact Indexed Array Using for and count()
- 4-18. Looping Through a Sparse Array
- Removing Elements from Arrays
- 4-19. Removing the First or Last Element from an Array
- 4-20. Removing One or More Arbitrary Array Elements
- 4-21. Extracting a Portion of an Array
- 4-22. Extracting Values from Arrays with extract()
- 4-23. Extracting Values from an Array Using list()
- 4-24. Combining Arrays
- 4-25. Obtaining Array Keys and Values
- 4-26. Working with Unique Values
- 4-27. Getting and Displaying Counts of Array Values
- Finding and Working with Array Values
- 4-28. Determining Whether an Element Is in an Array
- 4-29. Testing for the Existence of a Key in an Array
- 4-30. Obtaining Array Keys with a Given Value
- 4-31. Finding the Greatest and Least Values in an Array
- 4-32. Finding the Sum and Average of the Values in an Array
- Applying Functions to Arrays
- 4-33. Applying Functions to Array Elements Using array_walk()
- 4-34. Applying Functions to Array Elements Using array_map()
- 4-35. Filtering Arrays Using array_filter()
- Sorting Arrays
- 4-36. Sorting an Array by Its Values
- 4-37. Sorting an Array by Its Keys
- 4-38. Reversing an Array Using arsort()
- 4-39. Reversing an Array Using krsort()
- 4-40. Reversing an Array Using array_reverse()
- 4-41. Randomizing an Array Using shuffle(), kshuffle(), and array_rand()
- 4-42. Sorting an Array Using Comparison Functions
- 4-43. Sorting Multidimensional Arrays
- 4-44. Sorting Multiple Arrays
- Finding Permutations and Combinations
- 4-45. Finding All Permutations of an Array's Elements
- 4-46. Finding All Combinations of an Array's Elements
- Summary
- Looking Ahead
-
CHAPTER 5: Working with Dates and Times
- Overview of PHP 5's Date and Time Functions
- Displaying Dates and Times
- 5-1. Displaying Human-Readable Dates and Times
- 5-2. Displaying Arbitrary Dates and Times
- 5-3. Converting Human-Readable Dates Into Unix Timestamps Using strtotime()
- 5-4. Finding the Date for a Weekday
- 5-5. Getting the Day and Week of the Year
- 5-6. Determining Whether a Given Year Is a Leap Year
- 5-7. Getting Times and Dates of Files
- 5-8. Setting Time Zones and GMT/UTC
- 5-9. Displaying Times and Dates in Other Languages
- 5-10. Generating Localized GMT/UTC Time and Date Strings
- 5-11. Obtaining the Difference Between Two Dates
- 5-12. Project: Constructing and Using a Date Class
- 5-13. Extending the Date Class
- Summary
- Looking Ahead
-
CHAPTER 6: Working with Strings
- Manipulating Substrings
- 6-1. Testing for Substrings
- 6-2. Counting the Occurrences of a Substring
- 6-3. Accessing Substrings
- 6-4. Using Substring Alternatives
- 6-5. Replacing Substrings
- Processing Strings
- 6-6. Joining and Disassembling Strings
- 6-7. Reversing Strings
- 6-8. Controlling Case
- 6-9. Trimming Blank Spaces
- 6-10. Wrapping Text
- 6-11. Checking String Length
- 6-12. Comparing Strings
- 6-13. Comparing Sound
- Project: Creating and Using a String Class
- 6-14. Using a Page Reader Class
- Summary
- Looking Ahead
-
CHAPTER 7: Working with Files and Directories
- Working with Files
- 7-1. Opening Files
- 7-2. Reading from Files
- 7-3. Writing to Files
- 7-4. Closing Files
- 7-5. Reading and Writing Comma-Separated Data
- 7-6. Reading Fixed-Width Delimited Data
- 7-7. Reading and Writing Binary Data in a File
- 7-8. Getting the Number of Lines in a File
- 7-9. Getting the Number of Characters, Words, or Paragraphs in a File
- 7-10. Project: Creating and Using a File Class
- Working with Directories
- 7-11. Listing All Files in the Current Directory
- 7-12. Listing All Files of a Certain Type
- 7-13. Sorting Files by Date
- 7-14. Generating a Recursive Directory Listing
- 7-15. Using the SPL DirectoryIterator Object
- Summary
- Looking Ahead
-
CHAPTER 8: Working with Dynamic Imaging
- Working with Image Types
- 8-1. Working with JPGs
- 8-2. Working with GIFs
- 8-3. Working with PNGs
- Working with Image Libraries
- Creating an Image from Scratch
- 8-4. Creating a Blank Canvas
- 8-5. Creating and Using Colors
- 8-6. Creating and Applying Different Shapes and Patterns
- 8-7. Outputting an Image
- Creating an Image from an Existing Image
- 8-8. Loading an Existing Image
- 8-9. Applying Modifications to an Existing Image
- 8-10. Saving and Outputting the Modified Image
- Using TrueType Fonts
- 8-11. Loading Fonts
- 8-12. Applying TrueType Fonts to an Image
- 8-13. Project: Creating and Using a Dynamic Thumbnail Class
- Summary
- Looking Ahead
-
CHAPTER 9: Using Regular Expressions
- Overview of Regular Expression Syntax
- Qualifiers
- Ranges
- Line Anchors
- An Escape
- Saying OR
- Character Classes
- POSIX vs. PCRE
- POSIX
- PCRE
- Putting Regular Expressions to Work
- 9-1. Using String Matching vs. Pattern Matching
- 9-2. Finding the nth Occurrence of a Match
- 9-3. Matching with Greedy vs. Nongreedy Expressions
- 9-4. Matching a Valid IP Address
- 9-5. Validating Pascal Case Names
- 9-6. Validating U.S. Currency
- 9-7. Formatting a Phone Number
- 9-8. Finding Repeated Words
- 9-9. Finding Words Not Followed by Other Words
- 9-10. Matching a Valid E-mail Address
- 9-11. Finding All Matching Lines in a File
- 9-12. Finding Lines with an Odd Number of Quotes
- 9-13. Capturing Text Inside HTML or XML Tags
- 9-14. Escaping Special Characters
- 9-15. Replacing URLs with Links
- 9-16. Replacing Smart Quotes with Straight Quotes
- 9-17. Testing the Complexity of Passwords
- 9-18. Matching GUIDs/UUIDs
- 9-19. Reading Records with a Delimiter
- 9-20. Creating Your Own RegExp Class
- Summary
- Looking Ahead
-
CHAPTER 10: Working with Variables
- 10-1. Using Variable Types
- 10-2. Assigning and Comparing
- 10-3. Typecasting
- 10-4. Using Constants
- 10-5. Defining Variable Scope
- 10-6. Parsing Values to Functions
- 10-7. Using Dynamic Variable and Function Names
- 10-8. Encapsulating Complex Data Types
- 10-9. Sharing Variables Between Processes
- 10-10. Debugging
- Summary
- Looking Ahead
-
CHAPTER 11: Using Functions
- 11-1. Accessing Function Parameters
- 11-2. Setting Default Values for Function Parameters
- 11-3. Passing Values by Reference
- 11-4. Creating Functions That Take a Variable Number of Arguments
- 11-5. Returning More Than One Value
- 11-6. Returning Values by Reference
- 11-7. Returning Failure
- 11-8. Calling Variable Functions
- 11-9. Accessing a Global Variable from Within a Function
- 11-10. Creating Dynamic Functions
- Summary
- Looking Ahead
-
CHAPTER 12: Understanding Web Basics
- Using Cookies
- 12-1. Setting Cookies
- 12-2. Reading Cookies
- 12-3. Deleting Cookies
- 12-4. Writing and Using a Cookie Class
- Using HTTP Headers
- 12-5. Redirecting to a Different Location
- 12-6. Sending Content Types Other Than HTML
- 12-7. Forcing File “Save As” Downloads
- Using Sessions
- 12-8. Implementing Sessions
- 12-9. Storing Simple Data Types in Sessions
- 12-10. Storing Complex Data Types in Sessions
- 12-11. Detecting Browsers
- Using Querystrings
- 12-12. Using Querystrings
- 12-13. Passing Numeric Values in a Querystring
- 12-14. Passing String Values in a Querystring
- 12-15. Passing Complex Values in a Querystring
- Authenticating Your Users
- 12-16. Setting Up HTTP-Based Authentication
- 12-17. Setting Up Cookie Authentication
- Using Environment and Configuration Variables
- 12-18. Reading Environment and Configuration Variables
- 12-19. Setting Environment and Configuration Variables
- Summary
- Looking Ahead
-
CHAPTER 13: Creating and Using Forms
- Understanding Common Form Issues
- 13-1. GET vs. POST
- 13-2. Superglobals vs. Globals
- 13-3. Validating Form Input
- 13-4. Working with Multipage Forms
- 13-5. Redisplaying Forms with Preserved Information and Error Messages
- Preventing Multiple Submissions of a Form
- 13-6. Preventing Multiple Submissions on the Server Side
- 13-7. Preventing Multiple Submissions on the Client Side
- 13-8. Performing File Uploads
- 13-9. Handling Special Characters
- 13-10. Creating Form Elements with Multiple Options
- 13-11. Creating Form Elements Based on the Current Time and/or Date
- Summary
- Looking Ahead
- CHAPTER 14: Working with Markup
-
CHAPTER 15: Using MySQL Databases in PHP 5
- Basic Database Concepts
- 15-1. Connecting to a MySQL Database
- 15-2. Querying the Database
- 15-3. Retrieving and Displaying Results
- 15-4. Modifying Data
- 15-5. Deleting Data
- 15-6. Building Queries on the Fly
- The mysqli Extension vs. the PHP 4 MySQL Extension
- 15-7. Using the mysqli Object-Oriented API
- 15-8. Using Exceptions to Handle Database Errors
- 15-9. Project: Displaying Linked Search Results
- 15-10. Displaying Results in a Form
- Project: Bridging the Gap Between mysql and mysqli
- 15-11. Discovering Which Extension Is Being Used
- 15-12. Writing a Wrapper Class to Bridge the Gap
- 15-13. Project: Going from MySQL to XML and from XML to MySQL
- Summary
- Looking Ahead
- CHAPTER 16: Communicating with Internet Services
- Index
Product information
- Title: PHP 5 Recipes: A Problem-Solution Approach
- Author(s):
- Release date: October 2005
- Publisher(s): Apress
- ISBN: 9781590595091
You might also like
book
PHP and MySQL™ Phrasebook
gives you the code you need to complete your web programming projects quickly and effectively in …
book
Beginning PHP 5.3
Serving as a complete introduction to PHP 5.3, this book walks you through all the major …
book
PHP 7 Programming Cookbook
Over 80 recipes that will take your PHP 7 web development skills to the next level! …
book
PHP 5 Unleashed
Over 12 million Internet domains worldwide use the PHP language to power their websites. If you …