p. 3
php cookbook tm download at boykma.com
[close]
p. 4
other resources from o reilly related titles building scalable web sites essential php security learning php learning php and mysql php hackstm php in a nutshell programming php upgrading to php web database applications with php and mysql oreilly.com oreilly.com is more than a complete catalog of o reilly books you ll also find links to news events articles weblogs sample chapters and code examples oreillynet.com is the essential portal for developers interested in open and emerging technologies including new platforms programming languages and operating systems conferences o reilly brings diverse innovators together to nurture the ideas that spark revolutionary industries we specialize in documenting the latest tools and systems translating the innovator s knowledge into useful skills for those in the trenches visit conferences.oreilly.com for our upcoming events safari bookshelf safari.oreilly.com is the premier online reference library for programmers and it professionals conduct searches across more than 1,000 books subscribers can zero in on answers to time-critical questions in a matter of seconds read the books on your bookshelf from cover to cover or simply flip to the page you need try it today for free download at boykma.com
[close]
p. 5
second edition php cookbook tm adam trachtenberg and david sklar beijing · cambridge · farnham · köln · paris · sebastopol · taipei · tokyo download at boykma.com
[close]
p. 6
php cookbooktm second edition by david sklar and adam trachtenberg copyright © 2006 2002 o reilly media inc all rights reserved printed in the united states of america published by o reilly media inc 1005 gravenstein highway north sebastopol ca 95472 o reilly books may be purchased for educational business or sales promotional use online editions are also available for most titles safari.oreilly.com for more information contact our corporate/institutional sales department 800 998-9938 or corporate@oreilly.com editor tatiana apandi production editor adam witwer copyeditor adam witwer proofreader sada preisch printing history november 2002 august 2006 first edition second edition indexer joe wizda cover designer karen montgomery interior designer david futato illustrators robert romano and jessamyn read nutshell handbook the nutshell handbook logo and the o reilly logo are registered trademarks of o reilly media inc php cookbook the image of a galapagos land iguana and related trade dress are trademarks of o reilly media inc many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks where those designations appear in this book and o reilly media inc was aware of a trademark claim the designations have been printed in caps or initial caps while every precaution has been taken in the preparation of this book the publisher and author assume no responsibility for errors or omissions or for damages resulting from the use of the information contained herein this book uses repkovertm a durable and flexible lay-flat binding isbn-10 0-596-10101-5 isbn-13 978-0-596-10101-5 [m download at boykma.com
[close]
p. 7
table of contents preface xvii 1 strings 1 1.0 introduction 1.1 accessing substrings 1.2 extracting substrings 1.3 replacing substrings 1.4 processing a string one byte at a time 1.5 reversing a string by word or byte 1.6 expanding and compressing tabs 1.7 controlling case 1.8 interpolating functions and expressions within strings 1.9 trimming blanks from a string 1.10 generating comma-separated data 1.11 parsing comma-separated data 1.12 generating fixed-width field data records 1.13 parsing fixed-width field data records 1.14 taking strings apart 1.15 wrapping text at a certain line length 1.16 storing binary data in strings 1.17 program downloadable csv file 1 4 5 7 8 10 11 13 15 16 17 19 20 21 24 27 28 31 2 numbers 35 2.0 introduction 2.1 checking whether a variable contains a valid number 2.2 comparing floating-point numbers 2.3 rounding floating-point numbers 2.4 operating on a series of integers 2.5 generating random numbers within a range 2.6 generating biased random numbers 2.7 taking logarithms 2.8 calculating exponents 35 36 37 38 39 40 42 43 44 v download at boykma.com
[close]
p. 8
2.9 formatting numbers 2.10 formatting monetary values 2.11 printing correct plurals 2.12 calculating trigonometric functions 2.13 doing trigonometry in degrees not radians 2.14 handling very large or very small numbers 2.15 converting between bases 2.16 calculating using numbers in bases other than decimal 2.17 finding the distance between two places 45 46 48 49 50 51 53 54 55 3 dates and times 57 3.0 introduction 3.1 finding the current date and time 3.2 converting time and date parts to an epoch timestamp 3.3 converting an epoch timestamp to time and date parts 3.4 printing a date or time in a specified format 3.5 finding the difference of two dates 3.6 finding the difference of two dates with julian days 3.7 finding the day in a week month or year 3.8 validating a date 3.9 parsing dates and times from strings 3.10 adding to or subtracting from a date 3.11 calculating time with time zones 3.12 accounting for daylight savings time 3.13 generating a high-precision time 3.14 generating time ranges 3.15 using non-gregorian calendars 3.16 using dates outside the range of an epoch timestamp 3.17 program calendar 57 58 61 63 63 68 70 72 74 75 78 79 85 87 88 89 94 95 4 arrays 99 4.0 introduction 4.1 specifying an array not beginning at element 0 4.2 storing multiple elements per key in an array 4.3 initializing an array to a range of integers 4.4 iterating through an array 4.5 deleting elements from an array 4.6 changing array size 4.7 appending one array to another 4.8 turning an array into a string 4.9 printing an array with commas 4.10 checking if a key is in an array 4.11 checking if an element is in an array 99 101 103 104 105 107 109 111 113 114 115 116 vi table of contents download at boykma.com
[close]
p. 9
4.12 finding the position of a value in an array 4.13 finding elements that pass a certain test 4.14 finding the largest or smallest valued element in an array 4.15 reversing an array 4.16 sorting an array 4.17 sorting an array by a computable field 4.18 sorting multiple arrays 4.19 sorting an array using a method instead of a function 4.20 randomizing an array 4.21 removing duplicate elements from an array 4.22 applying a function to each element in an array 4.23 finding the union intersection or difference of two arrays 4.24 making an object act like an array 4.25 program printing a horizontally columned html table 117 118 119 120 121 122 124 126 127 127 128 130 132 135 5 variables 139 5.0 introduction 5.1 avoiding versus confusion 5.2 establishing a default value 5.3 exchanging values without using temporary variables 5.4 creating a dynamic variable name 5.5 using static variables 5.6 sharing variables between processes 5.7 encapsulating complex data types in a string 5.8 dumping variable contents as strings 139 140 141 142 143 144 145 150 151 6 functions 155 6.0 introduction 6.1 accessing function parameters 6.2 setting default values for function parameters 6.3 passing values by reference 6.4 using named parameters 6.5 creating functions that take a variable number of arguments 6.6 returning values by reference 6.7 returning more than one value 6.8 skipping selected return values 6.9 returning failure 6.10 calling variable functions 6.11 accessing a global variable inside a function 6.12 creating dynamic functions 155 156 157 158 159 161 163 165 166 168 169 171 172 7 classes and objects 175 7.0 introduction 175 table of contents vii download at boykma.com
[close]
p. 10
7.1 instantiating objects 7.2 defining object constructors 7.3 defining object destructors 7.4 implementing access control 7.5 preventing changes to classes and methods 7.6 defining object stringification 7.7 specifying interfaces 7.8 creating abstract base classes 7.9 assigning object references 7.10 cloning objects 7.11 overriding property accesses 7.12 calling methods on an object returned by another method 7.13 aggregating objects 7.14 accessing overridden methods 7.15 using method polymorphism 7.16 defining class constants 7.17 defining static properties and methods 7.18 controlling object serialization 7.19 introspecting objects 7.20 checking if an object is an instance of a specific class 7.21 autoloading class files upon object instantiation 7.22 instantiating an object dynamically 7.23 program whereis 179 180 181 182 185 186 189 191 193 194 196 201 201 205 206 208 210 212 214 218 220 222 223 8 web basics 227 8.0 introduction 8.1 setting cookies 8.2 reading cookie values 8.3 deleting cookies 8.4 redirecting to a different location 8.5 detecting different browsers 8.6 building a query string 8.7 reading the post request body 8.8 generating html tables with alternating row styles 8.9 using http basic or digest authentication 8.10 using cookie authentication 8.11 flushing output to the browser 8.12 buffering output to the browser 8.13 compressing web output 8.14 reading environment variables 8.15 setting environment variables 8.16 communicating within apache 8.17 program web site account deactivator 227 228 230 231 231 233 234 235 236 237 242 244 245 246 247 248 249 250 viii table of contents download at boykma.com
[close]
p. 11
8.18 program tiny wiki 253 9 form 257 9.0 introduction 9.1 processing form input 9.2 validating form input required fields 9.3 validating form input numbers 9.4 validating form input email addresses 9.5 validating form input drop-down menus 9.6 validating form input radio buttons 9.7 validating form input checkboxes 9.8 validating form input dates and times 9.9 validating form input credit cards 9.10 preventing cross-site scripting 9.11 working with multipage forms 9.12 redisplaying forms with inline error messages 9.13 guarding against multiple submission of the same form 9.14 processing uploaded files 9.15 preventing global variable injection 9.16 handling remote variables with periods in their names 9.17 using form elements with multiple options 9.18 creating drop-down menus based on the current date 257 259 260 262 264 266 268 269 270 271 273 274 275 278 279 282 284 285 286 10 database access 289 10.0 introduction 10.1 using dbm databases 10.2 using an sqlite database 10.3 connecting to an sql database 10.4 querying an sql database 10.5 retrieving rows without a loop 10.6 modifying data in an sql database 10.7 repeating queries efficiently 10.8 finding the number of rows returned by a query 10.9 escaping quotes 10.10 logging debugging information and errors 10.11 creating unique identifiers 10.12 building queries programmatically 10.13 making paginated links for a series of records 10.14 caching queries and results 10.15 accessing a database connection anywhere in your program 10.16 program storing a threaded message board 289 291 295 297 298 301 302 303 306 307 309 311 313 317 320 322 325 table of contents ix download at boykma.com
[close]
p. 12
11 sessions and data persistence 333 11.0 introduction 11.1 using session tracking 11.2 preventing session hijacking 11.3 preventing session fixation 11.4 storing sessions in a database 11.5 storing sessions in shared memory 11.6 storing arbitrary data in shared memory 11.7 caching calculated results in summary tables 333 334 335 337 338 340 344 346 12 xml 349 12.0 introduction 12.1 generating xml as a string 12.2 generating xml with the dom 12.3 parsing basic xml documents 12.4 parsing complex xml documents 12.5 parsing large xml documents 12.6 extracting information using xpath 12.7 transforming xml with xslt 12.8 setting xslt parameters from php 12.9 calling php functions from xslt stylesheets 12.10 validating xml documents 12.11 handling content encoding 12.12 reading rss and atom feeds 12.13 writing rss feeds 12.14 writing atom feeds 349 352 353 356 359 361 367 370 372 374 378 380 381 384 387 13 web automation 393 13.0 introduction 13.1 fetching a url with the get method 13.2 fetching a url with the post method 13.3 fetching a url with cookies 13.4 fetching a url with arbitrary headers 13.5 fetching a url with an arbitrary method 13.6 fetching a url with a timeout 13.7 fetching an https url 13.8 debugging the raw http exchange 13.9 marking up a web page 13.10 cleaning up broken or nonstandard html 13.11 extracting links from an html file 13.12 converting plain text to html 13.13 converting html to plain text 13.14 removing html and php tags x table of contents download at boykma.com 393 394 399 401 403 404 406 408 409 414 417 418 420 421 422
[close]
p. 13
13.15 responding to an ajax request 13.16 integrating with javascript 13.17 program finding stale links 13.18 program finding fresh links 423 426 429 432 14 consuming web services 437 14.0 introduction 14.1 calling a rest method 14.2 calling a soap method with wsdl 14.3 calling a soap method without wsdl 14.4 debugging soap requests 14.5 using complex soap types 14.6 setting soap types 14.7 using soap headers 14.8 using authentication with soap 14.9 redefining an endpoint 14.10 catching soap faults 14.11 mapping xml schema data types to php classes 14.12 calling an xml-rpc method 14.13 using authentication with xml-rpc 437 438 439 441 443 444 445 447 448 449 451 454 455 457 15 building web services 459 15.0 introduction 15.1 serving a rest method 15.2 serving a soap method 15.3 accepting arguments in a soap method 15.4 generating wsdl automatically 15.5 throwing soap faults 15.6 processing a soap header 15.7 generating a soap header 15.8 using authentication with soap 15.9 serving an xml-rpc method 459 459 465 468 470 470 473 475 477 482 16 internet services 487 16.0 introduction 16.1 sending mail 16.2 sending mime mail 16.3 reading mail with imap or pop3 16.4 posting messages to usenet newsgroups 16.5 reading usenet news messages 16.6 getting and putting files with ftp 16.7 looking up addresses with ldap 16.8 using ldap for user authentication 487 488 490 492 495 497 502 504 506 table of contents xi download at boykma.com
[close]
p. 14
16.9 performing dns lookups 16.10 checking if a host is alive 16.11 getting information about a domain name 508 509 511 17 graphics 515 17.0 introduction 17.1 drawing lines rectangles and polygons 17.2 drawing arcs ellipses and circles 17.3 drawing with patterned lines 17.4 drawing text 17.5 drawing centered text 17.6 building dynamic images 17.7 getting and setting a transparent color 17.8 reading exif data 17.9 serving images securely 17.10 program generating bar charts from poll results 515 518 520 521 523 525 530 532 533 535 537 18 security and encryption 541 18.0 introduction 18.1 preventing session fixation 18.2 protecting against form spoofing 18.3 ensuring input is filtered 18.4 avoiding cross-site scripting 18.5 eliminating sql injection 18.6 keeping passwords out of your site files 18.7 storing passwords 18.8 dealing with lost passwords 18.9 verifying data with hashes 18.10 encrypting and decrypting data 18.11 storing encrypted data in a file or database 18.12 sharing encrypted data with another web site 18.13 detecting ssl 18.14 encrypting email with gpg 541 542 543 544 545 546 547 548 550 551 553 558 561 563 564 19 internationalization and localization 567 19.0 introduction 19.1 listing available locales 19.2 using a particular locale 19.3 setting the default locale 19.4 localizing text messages 19.5 localizing dates and times 19.6 localizing currency values 19.7 localizing images xii table of contents download at boykma.com 567 569 569 570 571 575 576 580
[close]
p. 15
19.8 localizing included files 19.9 managing localization resources 19.10 using gettext 19.11 setting the character encoding of outgoing data 19.12 setting the character encoding of incoming data 19.13 manipulating utf-8 text 582 583 585 586 587 588 20 error handling debugging andtesting 593 20.0 introduction 20.1 finding and fixing parse errors 20.2 creating your own exception classes 20.3 printing a stack trace 20.4 reading configuration variables 20.5 setting configuration variables 20.6 hiding error messages from users 20.7 tuning error handling 20.8 using a custom error handler 20.9 logging errors 20.10 eliminating headers already sent errors 20.11 logging debugging information 20.12 using a debugger extension 20.13 writing a unit test 20.14 writing a unit test suite 20.15 applying a unit test to a web page 20.16 setting up a test environment 593 594 596 599 600 602 603 604 606 607 608 610 612 618 620 622 623 21 performance tuning and load testing 625 21.0 introduction 21.1 timing function execution 21.2 timing program execution 21.3 profiling with a debugger extension 21.4 stress testing your web site 21.5 avoiding regular expressions 21.6 using an accelerator 625 626 627 631 633 634 636 22 regular expressions 639 22.0 introduction 22.1 switching from ereg to preg 22.2 matching words 22.3 finding the nth occurrence of a match 22.4 choosing greedy or nongreedy matches 22.5 finding all lines in a file that match a pattern 22.6 capturing text inside html tags 639 642 644 645 646 648 649 table of contents xiii download at boykma.com
[close]