Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Programming PHP
Dedication
Foreword
Preface
Audience
Assumptions This Book Makes
Contents of This Book
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
Kevin Tatroe
Peter MacIntyre
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
2. Language Basics
Lexical Structure
Case Sensitivity
Statements and Semicolons
Whitespace and Line Breaks
Comments
Shell-style comments
C++ comments
C comments
Literals
Identifiers
Variable names
Function names
Class names
Constants
Keywords
Data Types
Integers
Floating-Point Numbers
Strings
Booleans
Arrays
Objects
Resources
Callbacks
NULL
Variables
Variable Variables
Variable References
Variable Scope
Local scope
Global scope
Static variables
Function parameters
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
Assignment
Assignment with operation
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
ASP Style
Script Style
Echoing Content Directly
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
4. Strings
Quoting String Constants
Variable Interpolation
Single-Quoted Strings
Double-Quoted Strings
Here Documents
Printing Strings
echo
print()
printf()
Format modifiers
Type specifiers
print_r() and var_dump()
Accessing Individual Characters
Cleaning Strings
Removing Whitespace
Changing Case
Encoding and Escaping
HTML
Entity-quoting all special characters
Entity-quoting only HTML syntax characters
Removing HTML tags
Extracting meta tags
URLs
RFC 3986 encoding and decoding
Query-string encoding
SQL
C-String Encoding
Comparing Strings
Exact Comparisons
Approximate Equality
Manipulating and Searching Strings
Substrings
Miscellaneous String Functions
Decomposing a String
Exploding and imploding
Tokenizing
sscanf()
String-Searching Functions
Searches returning position
Searches returning rest of string
Searches using masks
Decomposing URLs
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
Matching
Replacing
Splitting
Filtering an array with a regular expression
Quoting for regular expressions
Differences from Perl Regular Expressions
5. Arrays
Indexed Versus Associative Arrays
Identifying Elements of an Array
Storing Data in Arrays
Adding Values to the End of 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
Sets
Stacks
Iterator Interface
6. 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
Introspection
Examining Classes
Examining an Object
Sample Introspection Program
Serialization
7. 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
Session basics
Alternatives to cookies
Custom storage
Combining Cookies and Sessions
SSL
8. Databases
Using PHP to Access a Database
Relational Databases and SQL
PHP Data Objects
Making a connection
Interaction with the database
PDO and prepared statements
Transactions
MySQLi Object Interface
Retrieving Data for Display
SQLite
Direct File-Level Manipulation
MongoDB
Retrieving Data
Inserting More Complex Data
9. 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
10. 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
11. XML
Lightning Guide to XML
Generating XML
Parsing XML
Element Handlers
Character Data Handler
Processing Instructions
Entity Handlers
External entities
Unparsed entities
Default Handler
Options
Character encoding
Case folding
Using the Parser
Errors
Methods as Handlers
Sample Parsing Application
Parsing XML with DOM
Parsing XML with SimpleXML
Transforming XML with XSLT
12. Security
Filter Input
Cross-Site Scripting
SQL Injection
Escape Output
Filenames
Check for relative paths
Session Fixation
File Uploads
Distrust Browser-Supplied Filenames
Beware of Filling Your Filesystem
Surviving register_globals
File Access
Restrict Filesystem Access to a Specific Directory
Get It Right the First Time
Don’t Use Files
Session Files
Concealing PHP Libraries
PHP Code
Shell Commands
More Information
Security Recap
13. Application Techniques
Code Libraries
Templating Systems
Handling Output
Output Buffering
Compressing Output
Error Handling
Error Reporting
Error Suppression
Triggering Errors
Defining Error Handlers
Logging in error handlers
Output buffering in error handlers
Performance Tuning
Benchmarking
Profiling
Optimizing Execution Time
Optimizing Memory Requirements
Reverse Proxies and Replication
Reverse-proxy cache
Load balancing and redirection
MySQL replication
Putting it all together
14. PHP on Disparate Platforms
Writing Portable Code for Windows and Unix
Determining the Platform
Handling Paths Across Platforms
The Server Environment
Sending Mail
End-of-Line Handling
End-of-File Handling
External Commands
Common Platform-Specific Extensions
Interfacing with COM
Background
PHP Functions
Determining the API
15. Web Services
REST Clients
Responses
Retrieving Resources
Updating Resources
Creating Resources
Deleting Resources
XML-RPC
Servers
Clients
16. Debugging PHP
The Development Environment
The Staging Environment
The Production Environment
php.ini Settings
Manual Debugging
Error Log
IDE Debugging
Additional Debugging Techniques
17. Dates and Times
A. Function Reference
PHP Functions by Category
Arrays
Classes and Objects
Date and Time
Directories
Errors and Logging
Program Execution
Filesystem
Data Filtering
Functions
PHP Options/Info
Mail
Math
Miscellaneous Functions
Network
Output Buffering
Session Handling
Streams
Strings
PHP Language Tokenizer
URLs
Variables
Alphabetical Listing of PHP Functions
abs
acos
acosh
addcslashes
addslashes
array_change_key_case
array_chunk
array_combine
array_count_values
array_diff
array_diff_assoc
array_diff_key
array_diff_uassoc
array_diff_ukey
array_fill
array_fill_keys
array_filter
array_flip
array_intersect
array_intersect_assoc
array_intersect_key
array_intersect_uassoc
array_intersect_ukey
array_key_exists
array_keys
array_map
array_merge
array_merge_recursive
array_multisort
array_pad
array_pop
array_product
array_push
array_rand
array_reduce
array_replace
array_replace_recursive
array_reverse
array_search
array_shift
array_slice
array_splice
array_sum
array_udiff
array_udiff_assoc
array_udiff_uassoc
array_uintersect
array_uintersect_assoc
array_uintersect_uassoc
array_unique
array_unshift
array_values
array_walk
array_walk_recursive
arsort
asin
asinh
asort
assert
assert_options
atan
atan2
atanh
base_convert
base64_decode
base64_encode
basename
bin2hex
bindec
call_user_func
call_user_func_array
ceil
chdir
checkdate
checkdnsrr
chgrp
chmod
chown
chr
chroot
chunk_split
class_alias
class_exists
class_implements
class_parents
clearstatcache
closedir
closelog
compact
connection_aborted
connection_status
constant
convert_cyr_string
convert_uudecode
convert_uuencode
copy
cos
cosh
count
count_chars
crc32
create_function
crypt
current
date
date_default_timezone_set
date_default_timezone_get
date_parse
date_parse_from_format
date_sun_info
date_sunrise
date_sunset
debug_backtrace
debug_print_backtrace
decbin
dechex
decoct
define
define_syslog_variables
defined
deg2rad
dir
dirname
disk_free_space
disk_total_space
each
echo
empty
end
error_get_last
error_log
error_reporting
escapeshellarg
escapeshellcmd
exec
exp
explode
expm1
extension_loaded
extract
fclose
feof
fflush
fgetc
fgetcsv
fgets
fgetss
file
file_exists
fileatime
filectime
file_get_contents
filegroup
fileinode
filemtime
fileowner
fileperms
file_put_contents
filesize
filetype
filter_has_var
filter_id
filter_input
filter_input_array
filter_list
filter_var
filter_var_array
floatval
flock
floor
flush
fmod
fnmatch
fopen
forward_static_call
forward_static_call_array
fpassthru
fprintf
fputcsv
fread
fscanf
fseek
fsockopen
fstat
ftell
ftruncate
func_get_arg
func_get_args
func_num_args
function_exists
fwrite
gc_collect_cycles
gc_disable
gc_enable
gc_enabled
get_browser
get_called_class
get_cfg_var
get_class
get_class_methods
get_class_vars
get_current_user
get_declared_classes
get_declared_interfaces
get_declared_traits
get_defined_constants
get_defined_functions
get_defined_vars
get_extension_funcs
get_headers
get_html_translation_table
get_included_files
get_include_path
get_loaded_extensions
get_meta_tags
getmygid
getmyuid
get_object_vars
get_parent_class
get_resource_type
getcwd
getdate
getenv
gethostbyaddr
gethostbyname
gethostbynamel
gethostname
getlastmod
getmxrr
getmyinode
getmypid
getopt
getprotobyname
getprotobynumber
getrandmax
getrusage
getservbyname
getservbyport
gettimeofday
gettype
glob
gmdate
gmmktime
gmstrftime
header
header_remove
headers_list
headers_sent
hebrev
hebrevc
hex2bin
hexdec
highlight_file
highlight_string
htmlentities
html_entity_decode
htmlspecialchars
htmlspecialchars_decode
http_build_query
hypot
idate
ignore_user_abort
implode
inet_ntop
inet_pton
in_array
ini_get
ini_get_all
ini_restore
ini_set
interface_exists
intval
ip2long
is_a
is_array
is_bool
is_callable
is_dir
is_executable
is_file
is_finite
is_float
is_infinite
is_int
is_link
is_nan
is_null
is_numeric
is_object
is_readable
is_resource
is_scalar
is_string
is_subclass_of
is_uploaded_file
is_writable
isset
key
krsort
ksort
lcfirst
lcg_value
lchgrp
lchown
levenshtein
link
linkinfo
list
localeconv
localtime
log
log10
log1p
long2ip
lstat
ltrim
mail
max
md5
md5_file
memory_get_peak_usage
memory_get_usage
metaphone
method_exists
microtime
min
mkdir
mktime
money_format
move_uploaded_file
mt_getrandmax
mt_rand
mt_srand
natcasesort
natsort
next
nl_langinfo
nl2br
number_format
ob_clean
ob_end_clean
ob_end_flush
ob_flush
ob_get_clean
ob_get_contents
ob_get_flush
ob_get_length
ob_get_level
ob_get_status
ob_gzhandler
ob_implicit_flush
ob_list_handlers
ob_start
octdec
opendir
openlog
ord
output_add_rewrite_var
output_reset_rewrite_vars
pack
parse_ini_file
parse_ini_string
parse_str
parse_url
passthru
pathinfo
pclose
pfsockopen
php_ini_loaded_file
php_ini_scanned_files
php_logo_guid
php_sapi_name
php_strip_whitespace
php_uname
phpcredits
phpinfo
phpversion
pi
popen
pow
prev
print_r
printf
proc_close
proc_get_status
proc_nice
proc_open
proc_terminate
property_exists
putenv
quoted_printable_decode
quoted_printable_encode
quotemeta
rad2deg
rand
range
rawurldecode
rawurlencode
readdir
readfile
readlink
realpath
realpath_cache_get
realpath_cache_size
register_shutdown_function
register_tick_function
rename
reset
restore_error_handler
restore_exception_handler
restore_include_path
rewind
rewinddir
rmdir
round
rsort
rtrim
scandir
serialize
set_error_handler
set_exception_handler
set_include_path
set_time_limit
setcookie
setlocale
setrawcookie
settype
sha1
sha1_file
shell_exec
shuffle
similar_text
sin
sinh
sleep
sort
soundex
sprintf
sqrt
srand
sscanf
stat
str_getcsv
str_ireplace
str_pad
str_repeat
str_replace
str_rot13
str_shuffle
str_split
str_word_count
strcasecmp
strcmp
strcoll
strcspn
strftime
stripcslashes
stripslashes
strip_tags
stripos
stristr
strlen
strnatcasecmp
strnatcmp
strncasecmp
strncmp
strpbrk
strpos
strptime
strrchr
strrev
strripos
strrpos
strspn
strstr
strtok
strtolower
strtotime
strtoupper
strtr
strval
substr
substr_compare
substr_count
substr_replace
symlink
syslog
system
sys_getloadavg
sys_get_temp_dir
tan
tanh
tempnam
time
time_nanosleep
time_sleep_until
timezone_name_from_abbr
timezone_version_get
tmpfile
token_get_all
token_name
touch
trait_exists
trigger_error
trim
uasort
ucfirst
ucwords
uksort
umask
uniqid
unlink
unpack
unregister_tick_function
unserialize
unset
urldecode
urlencode
usleep
usort
var_dump
var_export
version_compare
vfprintf
vprintf
vsprintf
wordwrap
zend_logo_guid
zend_thread_id
zend_version
Index
About the Authors
Colophon
Copyright
← Prev
Back
Next →
← Prev
Back
Next →