PHP Cookbook

Front Cover
"O'Reilly Media, Inc.", 2003 - Computers - 608 pages

PHP is a simple yet powerful open source scripting language that has become a big player in web development. Over a million web sites, from large corporate sites to small personal sites, are using PHP to serve dynamic web content. PHP's broad feature set, approachable syntax, and support for different operating systems and web servers make it an ideal language for rapid web development.

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. For every problem addressed in the book, there's a worked-out solution or "recipe" -- short, focused pieces of code that you can insert directly into your applications. But this book offers more than cut-and-paste code. You also get explanations of how and why the code works, so you can learn to adapt the problem-solving techniques to similar situations.

The recipes in the PHP Cookbook range from simple tasks, such as sending a database query and fetching URLs, to entire programs that demonstrate complex tasks, such as printing HTML tables and generating bar charts. This book contains over 250 recipes on the following topics:

  • Working with basic data types, including strings, numbers, dates and times, and arrays
  • PHP building blocks, such as variables, functions, classes, and objects
  • Web programming, including forms, database access, and XML
  • Useful features like regular expressions, encryption and security, graphics, internationalization and localization, and Internet services
  • Working with files and directories
  • Command-line PHP and PHP-GTK
  • PEAR, the PHP Extension and Application Repository
This book contains an impressive collection of useful code for PHP programmers, from novices to advanced practitioners. Instead of poking around mailing lists, online documentation, and other sources, you can rely on the PHP Cookbook to provide quick solutions to common problems, so you can spend your time on those out-of-the-ordinary problems specific to your application.
 

Contents

II
1
III
3
IV
5
V
6
VI
7
VII
8
VIII
10
IX
12
CLXI
257
CLXII
258
CLXIII
259
CLXIV
262
CLXV
263
CLXVI
267
CLXVII
272
CLXVIII
274

X
13
XI
14
XII
15
XIII
17
XIV
20
XV
21
XVI
24
XVII
25
XVIII
26
XIX
27
XX
28
XXI
29
XXII
31
XXIII
32
XXV
33
XXVI
34
XXVII
36
XXVIII
37
XXX
39
XXXI
40
XXXII
42
XXXIII
43
XXXIV
46
XXXV
47
XXXVI
48
XXXVII
52
XXXVIII
54
XXXIX
55
XL
57
XLI
59
XLII
61
XLIII
62
XLIV
67
XLV
68
XLVI
69
XLVII
70
XLVIII
71
XLIX
75
L
78
LI
79
LII
80
LIII
81
LIV
83
LV
85
LVI
87
LVII
89
LVIII
91
LIX
92
LXI
94
LXII
95
LXIII
96
LXIV
97
LXV
98
LXVI
99
LXVII
101
LXVIII
103
LXIX
104
LXX
105
LXXI
106
LXXII
107
LXXIII
109
LXXIV
111
LXXV
114
LXXVI
117
LXXVII
118
LXXVIII
119
LXXIX
120
LXXXI
122
LXXXII
123
LXXXIII
125
LXXXIV
127
LXXXV
131
LXXXVI
132
LXXXVII
133
LXXXVIII
135
LXXXIX
136
XC
137
XCI
140
XCIII
142
XCIV
143
XCV
144
XCVI
145
XCVII
147
XCVIII
148
XCIX
152
C
153
CI
154
CIII
155
CIV
156
CV
157
CVI
159
CVII
160
CVIII
163
CIX
164
CX
165
CXI
166
CXII
168
CXIII
169
CXIV
171
CXVI
172
CXVII
173
CXVIII
175
CXIX
179
CXX
180
CXXI
182
CXXII
184
CXXIII
187
CXXV
189
CXXVI
190
CXXVII
191
CXXVIII
193
CXXIX
194
CXXX
195
CXXXI
197
CXXXII
199
CXXXIII
200
CXXXIV
201
CXXXV
202
CXXXVI
203
CXXXVII
204
CXXXVIII
208
CXXXIX
210
CXL
216
CXLI
218
CXLII
219
CXLIII
221
CXLIV
224
CXLV
227
CXLVI
229
CXLVII
231
CXLVIII
233
CXLIX
234
CL
235
CLI
236
CLII
238
CLIV
243
CLV
244
CLVI
248
CLVII
250
CLVIII
252
CLIX
254
CLX
255
CLXIX
281
CLXXI
282
CLXXII
285
CLXXIII
287
CLXXIV
289
CLXXV
290
CLXXVII
293
CLXXVIII
295
CLXXIX
296
CLXXX
297
CLXXXI
298
CLXXXII
299
CLXXXIII
301
CLXXXIV
303
CLXXXV
305
CLXXXVI
309
CLXXXVII
311
CLXXXVIII
313
CLXXXIX
316
CXC
319
CXCI
323
CXCII
326
CXCIII
329
CXCIV
333
CXCV
336
CXCVI
338
CXCVII
340
CXCVIII
343
CXCIX
346
CC
348
CCI
349
CCII
350
CCIII
352
CCIV
355
CCVI
357
CCVII
359
CCVIII
361
CCIX
362
CCX
363
CCXI
364
CCXII
366
CCXIII
367
CCXIV
369
CCXV
371
CCXVI
375
CCXVII
378
CCXVIII
380
CCXIX
381
CCXX
383
CCXXI
386
CCXXII
388
CCXXIII
390
CCXXIV
391
CCXXV
394
CCXXVI
398
CCXXVII
401
CCXXVIII
402
CCXXIX
403
CCXXX
408
CCXXXI
409
CCXXXII
410
CCXXXIII
411
CCXXXIV
412
CCXXXV
415
CCXXXVI
416
CCXXXVII
419
CCXXXVIII
420
CCXXXIX
421
CCXL
423
CCXLI
424
CCXLII
426
CCXLIV
427
CCXLV
430
CCXLVI
432
CCXLVII
435
CCXLVIII
437
CCXLIX
442
CCL
444
CCLI
446
CCLII
448
CCLIII
450
CCLIV
451
CCLV
454
CCLVII
457
CCLVIII
459
CCLIX
460
CCLXI
461
CCLXII
463
CCLXIII
465
CCLXIV
467
CCLXV
468
CCLXVII
469
CCLXVIII
470
CCLXIX
471
CCLXX
474
CCLXXI
475
CCLXXII
477
CCLXXIII
479
CCLXXV
480
CCLXXVI
481
CCLXXVII
483
CCLXXVIII
484
CCLXXIX
485
CCLXXX
486
CCLXXXI
489
CCLXXXII
490
CCLXXXIII
493
CCLXXXV
496
CCLXXXVI
497
CCLXXXVII
498
CCLXXXVIII
499
CCLXXXIX
501
CCXCI
502
CCXCII
503
CCXCIII
504
CCXCIV
507
CCXCV
508
CCXCVI
509
CCXCVII
514
CCXCVIII
518
CCXCIX
522
CCC
523
CCCI
527
CCCII
528
CCCIII
531
CCCIV
532
CCCV
535
CCCVI
537
CCCVII
540
CCCVIII
543
CCCIX
552
CCCXI
554
CCCXII
557
CCCXIII
558
CCCXIV
559
CCCXV
561
CCCXVI
563
CCCXVII
564
CCCXVIII
565
CCCXIX
569
Copyright

Other editions - View all

Common terms and phrases

About the author (2003)

Adam Trachtenberg has an MBA from Columbia Business School. At business school, he focused on general management and operations, with an emphasis on the field of technology. Adam also has a BA from Columbia University. As an undergraduate, he majored in mathematics and his other studies included computer science and Chinese. Before returning to school, he co-founded and served as Vice President for Development at two companies, Student.Com and TVGrid.Com. At both firms, he led the front- and middle-end web site design and development, worked on corporate planning and strategy, and served as liaison between the product and marketing teams. During study breaks, Adam enjoys playing squash, reading fiction, and eating in New York City's many wonderful restaurants. He wishes he was a better at playing pool, knew the constellations, and was handy around the house.