PHP Cookbook (2002).pdf

(2673 KB) Pobierz
Cookbook.PDF
PHP Cookbook
By David Sklar , Adam Trachtenberg
Publisher
: O'Reilly
Pub Date
: November 2002
ISBN
: 1-56592-681-1
Pages
: 632
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. It contains over 250
recipes, ranging from simple tasks to entire programs that demonstrate complex
tasks, such as printing HTML tables and generating bar charts -- a treasure
trove of useful code for PHP programmers, from novices to advanced
practitioners.
19072123.003.png 19072123.004.png
Copyright
Preface
Who This Book Is For
What Is in This Book
Other Resources
Conventions Used in This Book
Comments and Questions
Acknowledgments
Chapter 1. Strings
Section 1.1. Introduction
Recipe 1.2. Accessing Substrings
Recipe 1.3. Replacing Substrings
Recipe 1.4. Processing a String One Character at a Time
Recipe 1.5. Reversing a String by Word or Character
Recipe 1.6. Expanding and Compressing Tabs
Recipe 1.7. Controlling Case
Recipe 1.8. Interpolating Functions and Expressions Within Strings
Recipe 1.9. Trimming Blanks from a String
Recipe 1.10. Parsing Comma-Separated Data
Recipe 1.11. Parsing Fixed-Width Delimited Data
Recipe 1.12. Taking Strings Apart
Recipe 1.13. Wrapping Text at a Certain Line Length
Recipe 1.14. Storing Binary Data in Strings
Chapter 2. Numbers
Section 2.1. Introduction
Recipe 2.2. Checking Whether a String Contains a Valid Number
Recipe 2.3. Comparing Floating-Point Numbers
Recipe 2.4. Rounding Floating-Point Numbers
Recipe 2.5. Operating on a Series of Integers
Recipe 2.6. Generating Random Numbers Within a Range
Recipe 2.7. Generating Biased Random Numbers
Recipe 2.8. Taking Logarithms
Recipe 2.9. Calculating Exponents
Recipe 2.10. Formatting Numbers
Recipe 2.11. Printing Correct Plurals
Recipe 2.12. Calculating Trigonometric Functions
Recipe 2.13. Doing Trigonometry in Degrees, not Radians
Recipe 2.14. Handling Very Large or Very Small Numbers
Recipe 2.15. Converting Between Bases
Recipe 2.16. Calculating Using Numbers in Bases Other Than Decimal
19072123.005.png
Chapter 3. Dates and Times
Section 3.1. Introduction
Recipe 3.2. Finding the Current Date and Time
Recipe 3.3. Converting Time and Date Parts to an Epoch Timestamp
Recipe 3.4. Converting an Epoch Timestamp to Time and Date Parts
Recipe 3.5. Printing a Date or Time in a Specified Format
Recipe 3.6. Finding the Difference of Two Dates
Recipe 3.7. Finding the Difference of Two Dates with Julian Days
Recipe 3.8. Finding the Day in a Week, Month, Year, or the Week Number in a Year
Recipe 3.9. Validating a Date
Recipe 3.10. Parsing Dates and Times from Strings
Recipe 3.11. Adding to or Subtracting from a Date
Recipe 3.12. Calculating Time with Time Zones
Recipe 3.13. Accounting for Daylight Saving Time
Recipe 3.14. Generating a High-Precision Time
Recipe 3.15. Generating Time Ranges
Recipe 3.16. Using Non-Gregorian Calendars
Recipe 3.17. Program: Calendar
Chapter 4. Arrays
Section 4.1. Introduction
Recipe 4.2. Specifying an Array Not Beginning at Element 0
Recipe 4.3. Storing Multiple Elements per Key in an Array
Recipe 4.4. Initializing an Array to a Range of Integers
Recipe 4.5. Iterating Through an Array
Recipe 4.6. Deleting Elements from an Array
Recipe 4.7. Changing Array Size
Recipe 4.8. Appending One Array to Another
Recipe 4.9. Turning an Array into a String
Recipe 4.10. Printing an Array with Commas
Recipe 4.11. Checking if a Key Is in an Array
Recipe 4.12. Checking if an Element Is in an Array
Recipe 4.13. Finding the Position of an Element in an Array
Recipe 4.14. Finding Elements That Pass a Certain Test
Recipe 4.15. Finding the Largest or Smallest Valued Element in an Array
Recipe 4.16. Reversing an Array
Recipe 4.17. Sorting an Array
Recipe 4.18. Sorting an Array by a Computable Field
Recipe 4.19. Sorting Multiple Arrays
Recipe 4.20. Sorting an Array Using a Method Instead of a Function
Recipe 4.21. Randomizing an Array
Recipe 4.22. Shuffling a Deck of Cards
Recipe 4.23. Removing Duplicate Elements from an Array
19072123.006.png
Recipe 4.24. Finding the Union, Intersection, or Difference of Two Arrays
Recipe 4.25. Finding All Element Combinations of an Array
Recipe 4.26. Finding All Permutations of an Array
Recipe 4.27. Program: Printing an Array in a Horizontally Columned HTML Table
Chapter 5. Variables
Section 5.1. Introduction
Recipe 5.2. Avoiding == Versus = Confusion
Recipe 5.3. Establishing a Default Value
Recipe 5.4. Exchanging Values Without Using Temporary Variables
Recipe 5.5. Creating a Dynamic Variable Name
Recipe 5.6. Using Static Variables
Recipe 5.7. Sharing Variables Between Processes
Recipe 5.8. Encapsulating Complex Data Types as a String
Recipe 5.9. Dumping Variable Contents as Strings
Chapter 6. Functions
Section 6.1. Introduction
Recipe 6.2. Accessing Function Parameters
Recipe 6.3. Setting Default Values for Function Parameters
Recipe 6.4. Passing Values by Reference
Recipe 6.5. Using Named Parameters
Recipe 6.6. Creating Functions That Take a Variable Number of Arguments
Recipe 6.7. Returning Values by Reference
Recipe 6.8. Returning More Than One Value
Recipe 6.9. Skipping Selected Return Values
Recipe 6.10. Returning Failure
Recipe 6.11. Calling Variable Functions
Recipe 6.12. Accessing a Global Variable Inside a Function
Recipe 6.13. Creating Dynamic Functions
Chapter 7. Classes and Objects
Section 7.1. Introduction
Recipe 7.2. Instantiating Objects
Recipe 7.3. Defining Object Constructors
Recipe 7.4. Destroying an Object
Recipe 7.5. Cloning Objects
Recipe 7.6. Assigning Object References
Recipe 7.7. Calling Methods on an Object Returned by Another Method
Recipe 7.8. Accessing Overridden Methods
Recipe 7.9. Using Property Overloading
Recipe 7.10. Using Method Polymorphism
Recipe 7.11. Finding the Methods and Properties of an Object
19072123.001.png
Recipe 7.12. Adding Properties to a Base Object
Recipe 7.13. Creating a Class Dynamically
Recipe 7.14. Instantiating an Object Dynamically
Chapter 8. Web Basics
Section 8.1. Introduction
Recipe 8.2. Setting Cookies
Recipe 8.3. Reading Cookie Values
Recipe 8.4. Deleting Cookies
Recipe 8.5. Redirecting to a Different Location
Recipe 8.6. Using Session Tracking
Recipe 8.7. Storing Sessions in a Database
Recipe 8.8. Detecting Different Browsers
Recipe 8.9. Building a GET Query String
Recipe 8.10. Using HTTP Basic Authentication
Recipe 8.11. Using Cookie Authentication
Recipe 8.12. Flushing Output to the Browser
Recipe 8.13. Buffering Output to the Browser
Recipe 8.14. Compressing Web Output with gzip
Recipe 8.15. Hiding Error Messages from Users
Recipe 8.16. Tuning Error Handling
Recipe 8.17. Using a Custom Error Handler
Recipe 8.18. Logging Errors
Recipe 8.19. Eliminating "headers already sent" Errors
Recipe 8.20. Logging Debugging Information
Recipe 8.21. Reading Environment Variables
Recipe 8.22. Setting Environment Variables
Recipe 8.23. Reading Configuration Variables
Recipe 8.24. Setting Configuration Variables
Recipe 8.25. Communicating Within Apache
Recipe 8.26. Profiling Code
Recipe 8.27. Program: Website Account (De)activator
Recipe 8.28. Program: Abusive User Checker
Chapter 9. Forms
Section 9.1. Introduction
Recipe 9.2. Processing Form Input
Recipe 9.3. Validating Form Input
Recipe 9.4. Working with Multipage Forms
Recipe 9.5. Redisplaying Forms with Preserved Information and Error Messages
Recipe 9.6. Guarding Against Multiple Submission of the Same Form
Recipe 9.7. Processing Uploaded Files
Recipe 9.8. Securing PHP's Form Processing
19072123.002.png
Zgłoś jeśli naruszono regulamin