Programming PHP: Creating Dynamic Web Pages [4 ed.] 1492054135, 9781492054139

Why is PHP the most widely used programming language on the web? This updated edition teaches everything you need to kno

1,521 266 8MB

English Pages 540 [545] Year 2020

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Cover
Copyright
Table of Contents
Foreword
Preface
Audience
Assumptions This Book Makes
Contents of This Book
Conventions Used in This Book
O’Reilly Online Learning
How to Contact Us
Acknowledgments
Kevin Tatroe
Peter MacIntyre
Chapter 1. Introduction to PHP
What Does PHP Do?
A Brief History of PHP
The Evolution of PHP
The Widespread Use of PHP
Installing PHP
A Walk Through PHP
Configuration Page
Forms
Databases
Graphics
What’s Next
Chapter 2. Language Basics
Lexical Structure
Case Sensitivity
Statements and Semicolons
Whitespace and Line Breaks
Comments
Literals
Identifiers
Keywords
Data Types
Integers
Floating-Point Numbers
Strings
Booleans
Arrays
Objects
Resources
Callbacks
NULL
Variables
Variable Variables
Variable References
Variable Scope
Garbage Collection
Expressions and Operators
Number of Operands
Operator Precedence
Operator Associativity
Implicit Casting
Arithmetic Operators
String Concatenation Operator
Auto-Increment and Auto-Decrement Operators
Comparison Operators
Bitwise Operators
Logical Operators
Casting Operators
Assignment Operators
Miscellaneous Operators
Flow-Control Statements
if 
switch
while
for
foreach
try...catch
declare
exit and return
goto
Including Code
Embedding PHP in Web Pages
Standard (XML) Style
SGML Style
Echoing Content Directly
What’s Next
Chapter 3. Functions
Calling a Function
Defining a Function
Variable Scope
Global Variables
Static Variables
Function Parameters
Passing Parameters by Value
Passing Parameters by Reference
Default Parameters
Variable Parameters
Missing Parameters
Type Hinting
Return Values
Variable Functions
Anonymous Functions
What’s Next
Chapter 4. Strings
Quoting String Constants
Variable Interpolation
Single-Quoted Strings
Double-Quoted Strings
Here Documents
Printing Strings
echo
print()
printf()
print_r() and var_dump()
Accessing Individual Characters
Cleaning Strings
Removing Whitespace
Changing Case
Encoding and Escaping
HTML
URLs
SQL
C-String Encoding
Comparing Strings
Exact Comparisons
Approximate Equality
Manipulating and Searching Strings
Substrings
Miscellaneous String Functions
Decomposing a String
String-Searching Functions
Regular Expressions
The Basics
Character Classes
Alternatives
Repeating Sequences
Subpatterns
Delimiters
Match Behavior
Character Classes
Anchors
Quantifiers and Greed
Noncapturing Groups
Backreferences
Trailing Options
Inline Options
Lookahead and Lookbehind
Cut
Conditional Expressions
Functions
Differences from Perl Regular Expressions
What’s Next
Chapter 5. Arrays
Indexed Versus Associative Arrays
Identifying Elements of an Array
Storing Data in Arrays
Appending Values to an Array
Assigning a Range of Values
Getting the Size of an Array
Padding an Array
Multidimensional Arrays
Extracting Multiple Values
Slicing an Array
Splitting an Array into Chunks
Keys and Values
Checking Whether an Element Exists
Removing and Inserting Elements in an Array
Converting Between Arrays and Variables
Creating Variables from an Array
Creating an Array from Variables
Traversing Arrays
The foreach Construct
The Iterator Functions
Using a for Loop
Calling a Function for Each Array Element
Reducing an Array
Searching for Values
Sorting
Sorting One Array at a Time
Natural-Order Sorting
Sorting Multiple Arrays at Once
Reversing Arrays
Randomizing Order
Acting on Entire Arrays
Calculating the Sum of an Array
Merging Two Arrays
Calculating the Difference Between Two Arrays
Filtering Elements from an Array
Using Arrays to Implement Data Types
Sets
Stacks
Implementing the Iterator Interface
What’s Next
Chapter 6. Objects
Objects
Terminology
Creating an Object
Accessing Properties and Methods
Declaring a Class
Declaring Methods
Declaring Properties
Declaring Constants
Inheritance
Interfaces
Traits
Abstract Methods
Constructors
Destructors
Anonymous Classes
Introspection
Examining Classes
Examining an Object
Sample Introspection Program
Serialization
What’s Next
Chapter 7. Dates and Times
What’s Next
Chapter 8. Web Techniques
HTTP Basics
Variables
Server Information
Processing Forms
Methods
Parameters
Self-Processing Pages
Sticky Forms
Multivalued Parameters
Sticky Multivalued Parameters
File Uploads
Form Validation
Setting Response Headers
Different Content Types
Redirections
Expiration
Authentication
Maintaining State
Cookies
Sessions
Combining Cookies and Sessions
SSL
What’s Next
Chapter 9. Databases
Using PHP to Access a Database
Relational Databases and SQL
PHP Data Objects
MySQLi Object Interface
Retrieving Data for Display
SQLite
Direct File-Level Manipulation
MongoDB
Retrieving Data
Inserting More Complex Data
What’s Next
Chapter 10. Graphics
Embedding an Image in a Page
Basic Graphics Concepts
Creating and Drawing Images
The Structure of a Graphics Program
Changing the Output Format
Testing for Supported Image Formats
Reading an Existing File
Basic Drawing Functions
Images with Text
Fonts
TrueType Fonts
Dynamically Generated Buttons
Caching the Dynamically Generated Buttons
A Faster Cache
Scaling Images
Color Handling
Using the Alpha Channel
Identifying Colors
True Color Indexes
Text Representation of an Image
What’s Next
Chapter 11. PDF
PDF Extensions
Documents and Pages
A Simple Example
Initializing the Document
Outputting Basic Text Cells
Text
Coordinates
Text Attributes
Page Headers, Footers, and Class Extension
Images and Links
Tables and Data
What’s Next
Chapter 12. XML
Lightning Guide to XML
Generating XML
Parsing XML
Element Handlers
Character Data Handler
Processing Instructions
Entity Handlers
Default Handler
Options
Using the Parser
Errors
Methods as Handlers
Sample Parsing Application
Parsing XML with the DOM
Parsing XML with SimpleXML
Transforming XML with XSLT
What’s Next
Chapter 13. JSON
Using JSON
Serializing PHP Objects
Options
What’s Next
Chapter 14. Security
Safeguards
Filtering Input
Escaping Output Data
Security Vulnerabilities
Cross-Site Scripting
SQL Injection
Filename Vulnerabilities
Session Fixation
File Upload Traps
Unauthorized File Access
PHP Code Issues
Shell Command Weaknesses
Data Encryption Concerns
Further Resources
Security Recap
What’s Next
Chapter 15. Application Techniques
Code Libraries
Templating Systems
Handling Output
Output Buffering
Output Compression
Performance Tuning
Benchmarking
Profiling
Optimizing Execution Time
Optimizing Memory Requirements
Reverse Proxies and Replication
What’s Next
Chapter 16. Web Services
REST Clients
Responses
Retrieving Resources
Updating Resources
Creating Resources
Deleting Resources
XML-RPC
Servers
Clients
What’s Next
Chapter 17. Debugging PHP
The Development Environment
The Staging Environment
The Production Environment
php.ini Settings
Error Handling
Error Reporting
Exceptions
Error Suppression
Triggering Errors
Defining Error Handlers
Manual Debugging
Error Logs
IDE Debugging
Additional Debugging Techniques
What’s Next
Chapter 18. PHP on Disparate Platforms
Writing Portable Code for Windows and Unix
Determining the Platform
Handling Paths Across Platforms
Navigating the Server Environment
Sending Mail
End-of-Line Handling
End-of-File Handling
Using External Commands
Accessing Platform-Specific Extensions
Interfacing with COM
Background
PHP Functions
API Specifications
Function Reference
PHP Functions by Category
Arrays
Classes and Objects
Data Filtering
Date and Time
Directories
Errors and Logging
Filesystem
Functions
Mail
Math
Miscellaneous Functions
Network
Output Buffering
PHP Language Tokenizer
PHP Options/Info
Program Execution
Session Handling
Streams
Strings
URLs
Variables
Zlib
Alphabetical Listing of PHP Functions
Index
About the Authors
Colophon

Programming PHP: Creating Dynamic Web Pages [4 ed.]
 1492054135, 9781492054139

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers