Introduction |
|
1 | (7) |
|
|
|
PHP: From Home Page to Web Enterprise |
|
|
7 | (6) |
|
|
7 | (1) |
|
What Need Does PHP Fulfill? |
|
|
8 | (1) |
|
|
9 | (1) |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
11 | (1) |
|
|
11 | (1) |
|
What's New in This Edition |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
12 | (1) |
|
|
12 | (1) |
|
|
12 | (1) |
|
|
12 | (1) |
|
|
12 | (1) |
|
|
13 | (14) |
|
Platforms, Servers, Databases, and PHP |
|
|
13 | (1) |
|
Where to Find PHP and More |
|
|
14 | (1) |
|
Installing PHP for Linux and Apache |
|
|
14 | (3) |
|
|
17 | (2) |
|
|
17 | (1) |
|
|
17 | (1) |
|
|
18 | (1) |
|
|
18 | (1) |
|
|
19 | (1) |
|
|
19 | (1) |
|
|
20 | (2) |
|
|
21 | (1) |
|
Error Reporting Directives |
|
|
21 | (1) |
|
|
22 | (1) |
|
Changing php.ini Directives Locally |
|
|
22 | (1) |
|
|
22 | (2) |
|
|
24 | (1) |
|
|
24 | (1) |
|
|
25 | (1) |
|
|
25 | (1) |
|
|
25 | (1) |
|
|
25 | (2) |
|
|
27 | (14) |
|
|
27 | (6) |
|
Beginning and Ending a Block of PHP Statements |
|
|
30 | (2) |
|
|
32 | (1) |
|
|
33 | (2) |
|
Adding Comments to PHP Code |
|
|
35 | (1) |
|
|
35 | (1) |
|
|
36 | (1) |
|
|
36 | (1) |
|
|
36 | (1) |
|
|
37 | (1) |
|
|
37 | (4) |
|
|
|
|
41 | (22) |
|
|
41 | (2) |
|
|
43 | (7) |
|
Displaying Type Information with var_dump () |
|
|
46 | (1) |
|
Testing for a Specific Data Type |
|
|
46 | (1) |
|
Changing Type with settype () |
|
|
47 | (1) |
|
|
48 | (1) |
|
More Ways of Changing Type |
|
|
49 | (1) |
|
|
50 | (1) |
|
Operators and Expressions |
|
|
50 | (7) |
|
|
51 | (1) |
|
|
51 | (1) |
|
The Concatenation Operator |
|
|
52 | (1) |
|
Combined Assignment Operators |
|
|
52 | (1) |
|
|
53 | (1) |
|
Creating More Complex Test Expressions with the Logical Operators |
|
|
54 | (1) |
|
Automatically Incrementing and Decrementing an Integer Variable |
|
|
55 | (1) |
|
|
56 | (1) |
|
|
57 | (2) |
|
|
59 | (1) |
|
|
59 | (1) |
|
|
59 | (1) |
|
|
60 | (1) |
|
|
60 | (1) |
|
|
61 | (1) |
|
|
61 | (2) |
|
|
63 | (20) |
|
|
63 | (7) |
|
|
64 | (1) |
|
Using the else Clause with the if Statement |
|
|
65 | (1) |
|
Using the else if Clause with the if Statement |
|
|
66 | (1) |
|
|
67 | (2) |
|
|
69 | (1) |
|
|
70 | (7) |
|
|
70 | (1) |
|
The do . . . while Statement |
|
|
71 | (1) |
|
|
72 | (1) |
|
Breaking Out of Loops with the break Statement |
|
|
73 | (2) |
|
Skipping an Iteration with the continue Statement |
|
|
75 | (1) |
|
|
76 | (1) |
|
Code Blocks and Browser Output |
|
|
77 | (2) |
|
|
79 | (1) |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
80 | (1) |
|
|
80 | (1) |
|
|
81 | (2) |
|
|
83 | (24) |
|
|
83 | (1) |
|
|
84 | (1) |
|
|
85 | (2) |
|
Returning Values from User-Defined Functions |
|
|
87 | (1) |
|
|
88 | (1) |
|
|
89 | (4) |
|
Accessing Variables with the global Statement |
|
|
91 | (2) |
|
Saving State Between Function Calls with the static Statement |
|
|
93 | (3) |
|
|
96 | (4) |
|
Setting Default Values for Arguments |
|
|
96 | (2) |
|
Passing References to Variables to Functions |
|
|
98 | (1) |
|
Returning References from Functions |
|
|
99 | (1) |
|
Creating Anonymous Functions |
|
|
100 | (1) |
|
Testing for Function Existence |
|
|
101 | (2) |
|
|
103 | (1) |
|
|
103 | (1) |
|
|
104 | (1) |
|
|
104 | (1) |
|
|
105 | (1) |
|
|
105 | (2) |
|
|
107 | (22) |
|
|
107 | (1) |
|
|
108 | (2) |
|
Defining Arrays with the array () Construct |
|
|
108 | (1) |
|
Defining or Adding to Arrays with the Array Identifier |
|
|
109 | (1) |
|
Populating an Array with array_fill () |
|
|
110 | (1) |
|
|
110 | (1) |
|
Defining Associative Arrays with the array () Construct |
|
|
110 | (1) |
|
Directly Defining or Adding to an Associative Array |
|
|
111 | (1) |
|
|
111 | (2) |
|
|
113 | (6) |
|
Getting the Size of an Array |
|
|
113 | (1) |
|
|
114 | (1) |
|
Looping Through an Associative Array |
|
|
115 | (1) |
|
Outputting a Multidimensional Array |
|
|
116 | (2) |
|
Examining Arrays with print_r () |
|
|
118 | (1) |
|
|
119 | (4) |
|
Joining Two Arrays with array_merge () |
|
|
120 | (1) |
|
Adding Multiple Variables to an Array |
|
|
120 | (1) |
|
Removing the First Element of an Array with array_shift () |
|
|
121 | (1) |
|
Slicing Arrays with array_slice () |
|
|
122 | (1) |
|
|
123 | (2) |
|
Sorting Numerically Indexed Arrays with sort () |
|
|
123 | (1) |
|
Sorting an Associative Array by Value with asort () |
|
|
123 | (1) |
|
Sorting an Associative Array by Key with ksort () |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
127 | (1) |
|
|
127 | (1) |
|
|
127 | (1) |
|
|
128 | (1) |
|
|
128 | (1) |
|
|
129 | (26) |
|
|
129 | (9) |
|
|
129 | (4) |
|
|
133 | (4) |
|
|
137 | (1) |
|
Storing a Formatted String |
|
|
138 | (1) |
|
|
138 | (4) |
|
A Note About Indexing Strings |
|
|
138 | (1) |
|
Finding the Length of a String with strlen () |
|
|
138 | (1) |
|
Finding a Substring Within a String with strstr () |
|
|
139 | (1) |
|
Finding the Position of a Substring with strpos () |
|
|
139 | (1) |
|
Extracting Part of a String with substr () |
|
|
140 | (1) |
|
Tokenizing a String with strtok () |
|
|
140 | (2) |
|
|
142 | (9) |
|
Cleaning Up a String with trim (), ltrim (), and strip_tags () |
|
|
142 | (1) |
|
Replacing a Portion of a String Using substr_replace () |
|
|
143 | (1) |
|
Replacing Substring Using str_replace () |
|
|
144 | (1) |
|
|
145 | (1) |
|
Wrapping Text with wordwrap () and n12br () |
|
|
146 | (1) |
|
Breaking Strings into Arrays with explode () |
|
|
147 | (1) |
|
Formatting Numbers As Text |
|
|
147 | (4) |
|
|
151 | (1) |
|
|
152 | (1) |
|
|
152 | (1) |
|
|
152 | (1) |
|
|
153 | (1) |
|
|
153 | (2) |
|
|
155 | (26) |
|
|
155 | (1) |
|
|
156 | (1) |
|
|
157 | (1) |
|
|
158 | (3) |
|
|
159 | (2) |
|
Limiting Access to Object Properties |
|
|
161 | (2) |
|
Limiting Access to Object Methods |
|
|
163 | (1) |
|
Constraining Arguments to Methods with Hints |
|
|
164 | (2) |
|
|
166 | (4) |
|
Overriding the Method of a Parent Class |
|
|
167 | (1) |
|
Calling an Overridden Method |
|
|
168 | (1) |
|
Working with Constructors |
|
|
169 | (1) |
|
Testing Classes and Objects |
|
|
170 | (2) |
|
Finding the Class of an Object |
|
|
170 | (1) |
|
Finding the Family of an Object |
|
|
171 | (1) |
|
Checking for Class and Method Existence |
|
|
172 | (1) |
|
Automatically Loading Include Files with_autoload () |
|
|
172 | (1) |
|
Storing and Retrieving Objects |
|
|
173 | (1) |
|
|
174 | (1) |
|
|
175 | (1) |
|
|
175 | (3) |
|
|
175 | (1) |
|
|
176 | (2) |
|
|
178 | (3) |
|
Part III: Working with PHP |
|
|
|
|
181 | (22) |
|
|
181 | (1) |
|
|
182 | (2) |
|
A Script to Acquire User Input |
|
|
184 | (2) |
|
Importing User Input into Global Scope |
|
|
186 | (1) |
|
Accessing Form Input with User-Defined Arrays |
|
|
186 | (2) |
|
Combining HTML and PHP Code on a Single Page |
|
|
188 | (3) |
|
Using Hidden Fields to Save State |
|
|
191 | (2) |
|
|
193 | (2) |
|
File Upload Forms and Scripts |
|
|
195 | (4) |
|
|
199 | (1) |
|
|
199 | (1) |
|
|
199 | (2) |
|
|
199 | (1) |
|
|
200 | (1) |
|
|
201 | (2) |
|
|
203 | (24) |
|
Including Files with include () |
|
|
203 | (4) |
|
Returning a Value from an Included Document |
|
|
205 | (1) |
|
Using include () Within Control Structures |
|
|
206 | (1) |
|
|
207 | (1) |
|
Using include_once () and include_path to Manage Larger Projects |
|
|
207 | (2) |
|
|
209 | (4) |
|
Checking for Existence with file_exists () |
|
|
209 | (1) |
|
|
209 | (1) |
|
Checking the Status of a File |
|
|
210 | (1) |
|
Determining File Size with filesize () |
|
|
210 | (1) |
|
Getting Date Information About a File |
|
|
210 | (1) |
|
Creating a Function That Performs Multiple File Tests |
|
|
211 | (2) |
|
Creating and Deleting Files |
|
|
213 | (1) |
|
Opening a File for Writing, Reading, or Appending |
|
|
213 | (1) |
|
|
214 | (4) |
|
Reading Lines from a File with fgets () and feof () |
|
|
214 | (2) |
|
Reading Arbitrary Amounts of Data from a File with fread () |
|
|
216 | (1) |
|
Reading Characters from a File with fgetc () |
|
|
217 | (1) |
|
Reading the Contents of a File with file_get_contents () |
|
|
218 | (1) |
|
Writing or Appending to a File |
|
|
218 | (1) |
|
Writing to a File with fwrite () or fputs () |
|
|
219 | (1) |
|
Writing Data to a File with file_put_contents () |
|
|
219 | (2) |
|
Locking Files with flock () |
|
|
220 | (1) |
|
|
221 | (2) |
|
Creating Directories with mkdir () |
|
|
221 | (1) |
|
Removing a Directory with rmdir () |
|
|
221 | (1) |
|
Opening a Directory for Reading with opendir () |
|
|
221 | (1) |
|
Reading the Contents of a Directory with readdir () |
|
|
222 | (1) |
|
|
223 | (1) |
|
|
223 | (1) |
|
|
224 | (1) |
|
|
224 | (1) |
|
|
225 | (1) |
|
|
225 | (2) |
|
Working with the DBA Functions |
|
|
227 | (18) |
|
|
227 | (2) |
|
|
229 | (1) |
|
Adding Data to the Database |
|
|
230 | (1) |
|
Amending Elements in a Database |
|
|
231 | (1) |
|
|
231 | (3) |
|
Determining Whether an Item Exists in a Database |
|
|
234 | (1) |
|
Deleting an Item from a Database |
|
|
234 | (1) |
|
Adding Complex Data Structures to a Database |
|
|
234 | (4) |
|
|
238 | (5) |
|
|
243 | (1) |
|
|
243 | (1) |
|
|
244 | (1) |
|
|
244 | (1) |
|
|
244 | (1) |
|
|
244 | (1) |
|
Database Integration---SQL |
|
|
245 | (26) |
|
A (Very) Brief Introduction to SQL |
|
|
245 | (2) |
|
Connecting to the MySQL Database Server |
|
|
247 | (1) |
|
|
248 | (1) |
|
|
249 | (1) |
|
|
250 | (3) |
|
Acquiring the Value of an Automatically Incremented Field |
|
|
253 | (1) |
|
|
254 | (4) |
|
Finding the Number of Rows Found by a Query |
|
|
254 | (1) |
|
|
255 | (3) |
|
|
258 | (2) |
|
SQLite: A Lightweight SQL Engine |
|
|
260 | (2) |
|
Creating a Table in a SQLite Database |
|
|
260 | (1) |
|
Entering and Updating Data |
|
|
261 | (1) |
|
|
262 | (1) |
|
Using the PEAR DB Package |
|
|
262 | (6) |
|
Installing the PEAR::DB Package |
|
|
263 | (1) |
|
Working with the PEAR::DB Package |
|
|
263 | (5) |
|
|
268 | (1) |
|
|
268 | (1) |
|
|
269 | (1) |
|
|
269 | (1) |
|
|
269 | (1) |
|
|
270 | (1) |
|
|
271 | (24) |
|
Server Variables Revisited |
|
|
271 | (3) |
|
A Brief Summary of an HTTP Client/Server Negotiation |
|
|
274 | (4) |
|
|
274 | (2) |
|
|
276 | (2) |
|
Getting a Document from a Remote Address |
|
|
278 | (1) |
|
Converting IP Addresses and Hostnames |
|
|
279 | (1) |
|
Making a Network Connection |
|
|
280 | (6) |
|
Making an NNTP Connection Using fsockopen () |
|
|
284 | (2) |
|
Sending Mail with the mail () Function |
|
|
286 | (1) |
|
An Introduction to Streams |
|
|
287 | (4) |
|
|
288 | (3) |
|
|
291 | (1) |
|
|
291 | (1) |
|
|
292 | (1) |
|
|
292 | (1) |
|
|
292 | (1) |
|
|
293 | (2) |
|
|
295 | (26) |
|
Checking Your Configuration with gd_info () |
|
|
295 | (2) |
|
Creating and Outputting Images |
|
|
297 | (1) |
|
|
297 | (2) |
|
|
299 | (2) |
|
|
301 | (1) |
|
|
302 | (1) |
|
|
303 | (1) |
|
|
304 | (1) |
|
Making a Color Transparent |
|
|
305 | (1) |
|
|
306 | (7) |
|
Writing to an Image with the imagestring () Function |
|
|
306 | (1) |
|
Working with TrueType Fonts |
|
|
307 | (1) |
|
Writing a String with imageTTFtext () |
|
|
308 | (1) |
|
Testing Text Dimensions with imageTTFbox () |
|
|
309 | (4) |
|
|
313 | (5) |
|
|
318 | (1) |
|
|
319 | (1) |
|
|
319 | (1) |
|
|
319 | (1) |
|
|
319 | (1) |
|
|
320 | (1) |
|
Working with Dates and Times |
|
|
321 | (22) |
|
Getting the Date with time () |
|
|
321 | (1) |
|
Converting a Timestamp with getdate () |
|
|
322 | (2) |
|
Converting a Timestamp with date () |
|
|
324 | (2) |
|
Creating Timestamps with mktime () |
|
|
326 | (1) |
|
Testing a Date with checkdate () |
|
|
327 | (1) |
|
|
327 | (7) |
|
|
327 | (2) |
|
|
329 | (2) |
|
|
331 | (1) |
|
|
332 | (2) |
|
|
334 | (6) |
|
|
340 | (1) |
|
|
340 | (1) |
|
|
341 | (1) |
|
|
341 | (1) |
|
|
341 | (1) |
|
|
341 | (2) |
|
|
343 | (26) |
|
|
343 | (2) |
|
|
345 | (1) |
|
|
346 | (2) |
|
Intercepting Calls to Object Properties and Methods |
|
|
348 | (4) |
|
|
352 | (1) |
|
Cleaning Up Using Destructors |
|
|
352 | (2) |
|
Managing Error Conditions with Exceptions |
|
|
354 | (3) |
|
Defining Custom Exception Classes |
|
|
355 | (2) |
|
Tools for Building Object Hierarchies |
|
|
357 | (7) |
|
|
358 | (3) |
|
|
361 | (3) |
|
Passing and Assigning Objects |
|
|
364 | (1) |
|
|
365 | (1) |
|
|
365 | (1) |
|
|
366 | (1) |
|
|
366 | (1) |
|
|
366 | (1) |
|
|
367 | (2) |
|
Working with Regular Expressions |
|
|
369 | (20) |
|
Perl Compatible Regular Expressions |
|
|
369 | (17) |
|
Matching Patterns with preg_match () |
|
|
370 | (7) |
|
Finding Matches Globally with preg_match_all () |
|
|
377 | (3) |
|
Using preg_replace () to Replace Patterns |
|
|
380 | (1) |
|
|
381 | (3) |
|
Using preg_replace_callback () to Replace Patterns |
|
|
384 | (1) |
|
Using preg_split () to Break Up Strings |
|
|
385 | (1) |
|
|
386 | (1) |
|
|
386 | (1) |
|
|
386 | (2) |
|
|
386 | (1) |
|
|
387 | (1) |
|
|
388 | (1) |
|
Saving State with Cookies and Query Strings |
|
|
389 | (16) |
|
|
389 | (2) |
|
|
390 | (1) |
|
Setting a Cookie with PHP |
|
|
391 | (10) |
|
|
393 | (1) |
|
|
393 | (1) |
|
An Example---Tracking Site Usage |
|
|
393 | (8) |
|
Working with the Query String |
|
|
401 | (1) |
|
|
401 | (2) |
|
|
403 | (1) |
|
|
403 | (1) |
|
|
404 | (1) |
|
|
404 | (1) |
|
|
404 | (1) |
|
|
404 | (1) |
|
Saving State with Session Functions |
|
|
405 | (12) |
|
What Are Session Functions? |
|
|
405 | (1) |
|
Starting a Session with session_start () |
|
|
406 | (1) |
|
Working with Session Variables |
|
|
407 | (5) |
|
Destroying Sessions and Unsetting Elements |
|
|
412 | (1) |
|
Passing Session IDs in the Query String |
|
|
413 | (1) |
|
Encoding and Decoding Session Variables |
|
|
413 | (1) |
|
|
414 | (1) |
|
|
415 | (1) |
|
|
415 | (1) |
|
|
415 | (1) |
|
|
416 | (1) |
|
|
416 | (1) |
|
Working with the Server Environment |
|
|
417 | (16) |
|
Opening Pipes to and from Processes with popen () and proc_open () |
|
|
417 | (7) |
|
Running Commands with exec () |
|
|
424 | (1) |
|
Running External Commands with system () or the Backtick Operator |
|
|
425 | (1) |
|
Plugging Security Holes with escapeshellcmd () |
|
|
426 | (3) |
|
Running External Applications with passthru () |
|
|
429 | (1) |
|
Calling an External CGI Script with the virtual () Function |
|
|
430 | (1) |
|
|
430 | (1) |
|
|
431 | (1) |
|
|
431 | (1) |
|
|
431 | (1) |
|
|
432 | (1) |
|
|
432 | (1) |
|
|
433 | (26) |
|
|
433 | (3) |
|
|
436 | (7) |
|
Acquiring a Parser Resource |
|
|
436 | (1) |
|
|
437 | (1) |
|
|
438 | (1) |
|
|
439 | (1) |
|
|
439 | (2) |
|
|
441 | (2) |
|
An Introduction to the DOM XML Functions |
|
|
443 | (8) |
|
Acquiring a DomDocument Object |
|
|
444 | (1) |
|
|
444 | (1) |
|
Adding New DomElement Objects to the Tree |
|
|
445 | (2) |
|
Getting Information from DomElement Objects |
|
|
447 | (1) |
|
|
448 | (1) |
|
Traversing a Tree: Two Approaches |
|
|
449 | (2) |
|
|
451 | (2) |
|
|
451 | (1) |
|
|
451 | (2) |
|
Applying XSL to XML with PHP |
|
|
453 | (1) |
|
|
453 | (1) |
|
|
454 | (1) |
|
|
455 | (1) |
|
|
455 | (1) |
|
|
455 | (1) |
|
|
456 | (1) |
|
|
456 | (3) |
|
|
|
PEAR: Reusable Components to Extend the Power of PHP |
|
|
459 | (26) |
|
|
459 | (2) |
|
|
460 | (1) |
|
|
460 | (1) |
|
|
461 | (1) |
|
Some PEAR Packages in Action |
|
|
461 | (19) |
|
|
461 | (8) |
|
The PhpDocumentor Package |
|
|
469 | (6) |
|
Editing Configuration Files with the Config Package |
|
|
475 | (5) |
|
|
480 | (1) |
|
|
480 | (1) |
|
|
481 | (1) |
|
|
482 | (1) |
|
|
482 | (1) |
|
|
482 | (1) |
|
|
483 | (1) |
|
|
483 | (2) |
|
Toward a Framework for Larger Projects |
|
|
485 | (30) |
|
|
485 | (2) |
|
|
487 | (2) |
|
The RequestHelper and DataStore Classes |
|
|
489 | (4) |
|
|
493 | (3) |
|
|
496 | (1) |
|
|
497 | (4) |
|
Working with the Framework |
|
|
501 | (10) |
|
Implementing ApplicationResources |
|
|
502 | (2) |
|
|
504 | (2) |
|
|
506 | (2) |
|
|
508 | (3) |
|
Where Now, and Was It Worth It? |
|
|
511 | (1) |
|
|
512 | (1) |
|
|
513 | (1) |
|
|
513 | (1) |
|
|
513 | (1) |
|
|
514 | (1) |
|
|
514 | (1) |
Glossary |
|
515 | (10) |
Index |
|
525 | |