OReilly.PHP.Cookbook.3rd.Edition

所需积分/C币:9 2016-11-01 20:19:30 9.13MB PDF
7
收藏 收藏
举报

OReilly.PHP.Cookbook.3rd.Edition
HIRD EDITION PHP Cookbook David Sklar and adam Trachtenberg Beijing· Cambridge.mham·Kh· Sebastopol. TokyoOREILLY PHP Cookbook. third edition by David Sklar and Adam Trachtenberg Copyright@ 2014 David Sklar and Adam Trachtenberg. All rights reserved Printed in the United States of america Published by Oreilly Media, InC, 1005 Gravenstein Highway North, Sebastopol, CA 95472 OReilly books may be purchased for educational,business, or sales promotional use. Online editions are alsoavailableformosttitles(http://my.safaribooksonline.com).fOrmoreinformationcontactourcorporate institutionalsalesdepartment:800-998-9938orcorporate@oreilly.com Editors: Rachel Roumeliotis and Allyson MacDonald Indexer: Judith Mcconville Production Editor: Melanie Yarbrough Cover Designer: Karen Montgomery 〔 .opyeditor:: Kim Cofer Interior Designer: David Futato Proofreader: Charles roumeliotis strator: Rebecca demarest June 2001 First edition June 2004 Second edition June 2014 Third edition Revision history for the Third Edition: 2014-06-25: First release Seehttp://oreilly.com/catalog/errata.csp?isbn=9781449363758forreleasedetails Nutshell Handbook, the Nutshell Handbook logo, and the O Reilly logo are registered trademarks ofO 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 ofa 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 authors assume no responsibility forerrors or omissions, or for damages resulting from the use of the information contained herein ISBN:978-1-449-36375-8 Table of contents Preface things. 1.1 Accessing Substrings 1.2 Extracting Substrings 1.3 Replacing Substrings 1. 4 Processing a String One Byte at a Time 6790 1.5 Reversing a String by Word or Byte 1.6 Generating a Random String 11 1.7 Expanding and Compressing Tabs 1.8 Controlling Case 1.9 Interpolating Functions and Expressions Within Strings 246 1. 10 Trimming Blanks from a String 1.11 Generating Comma-Separated Data 18 1. 12 Parsing Comma-Separated Data 20 1. 13 Generating Fixed-Width Field Data Records 21 1. 14 Parsing Fixed-Width Field Data Records 22 1.15 Taking Strings Apart 25 1. 16 Wrapping Text at a Certain Line Length 27 1. 17 Storing Binary Data in Strings 28 1.18 Program: Downloadable Csv File 31 2. Numbers ,35 2.1 Checking Whether a Variable Contains a Valid Number 36 2.2 Comparing Floating-Point Numbers 37 2.3 Rounding Floating-Point Numbers 38 2. 4 Operating on a series of Integers 2.5 Generating Random Numbers Within a Range 42 2.6 Generating Predictable Random Numbers 43 2.7 Generating Biased Random Numbers 2. 8 Taking logarithms 2.9 Calculating exponents 2.10 Formatting Numbers 47 2. 11 Formatting Monetary Values 2.12 Printing Correct Plurals 50 2.13 Calculating Trigonometric Functions 51 2. 14 Doing Trigonometry in Degrees, Not Radians 52 2. 15 Handling Very Large or Very Small Numbers 53 2. 16 Converting between bases 55 2. 17 Calculating Using Numbers in Bases Other Than Decimal 56 2. 18 Finding the distance between Two places 58 3. Dates and times 鲁鲁鲁鲁·鲁 61 3. 1 Finding the Current Date and Time 3.2 Converting Time and Date Parts to an Epoch Timestamp 66 3.3 Converting an Epoch Timestamp to Time and Date Parts 68 3.4 Printing a Date or Time in a Specified Format 3.5 Finding the Difference of Two Dates 71 3.6 Finding the Day in a Week, Month, or Year 73 3.7 Validating a Date 3.8 Parsing Dates and Times from Strings 3.9 Adding to or Subtracting from a date 79 3. 10 Calculating Time with Time Zones and Daylight Saving Time 80 3. 11 Generating a High-Precision Time 82 3.12 Generating Time Ranges 83 3. 13 USing Non-Gregorian Calendars 84 3. 14 Program: Calendar 87 4. Arrays. 4. 1 Specifying an Array Not Beginning at Element 0 96 4.2 Storing Multiple Elements per Key in an array 4.3 Initializing an Array to a Range of integers 9 4.4 Iterating Through an Array 99 4.5 Deleting Elements from an Array 102 4.6 Changing Array Size 104 4.7 Appending One Array to Another 106 4.8 Turning an Array into a String 108 4.9 Printing an array with Commas 109 4. 10 Checking if a Key Is in an Array 110 4.11 Checking if an Element Is in an Array 4.12 Finding the Position of a Value in an Array 113 Table of contents 4.13 Finding Elements That Pass a Certain Test 114 4. 14 Finding the Largest or Smallest Valued Element in an Array 115 4.15 Reversing an Array 116 4.16 Sorting an Array 4. 17 Sorting an array by a Computable Field 118 4.18 Sorting Multiple arrays 120 4.19 Sorting an array using a method Instead of a Function 122 4.20 Randomizing an array 123 4.21 Removing Duplicate Elements from an Array 123 4.22 Applying a Function to Each Element in an Array 124 4.23 Finding the Union, Intersection, or Difference of Two arrays 126 4.24 Iterating efficiently over Large or Expensive Datasets 128 4. 25 Accessing an Object Using Array Syntax 131 5. Variables 135 5. 1 Avoiding Versus= confusion 5.2 Establishing a Default value 138 5.3 Exchanging Values Without Using Temporary Variables 139 5.4 Creating a dynamic variable Name 140 5.5 Persisting a Local Variable's Value Across Function Invocations 141 5.6 Sharing variables Between Processes 143 5.7 Encapsulating Complex Data Types in a String 149 5.8 Dumping Variable Contents as Strings 151 6. Functions 157 6. 1 Accessing Function Parameters 158 6.2 Setting Default Values for Function Parameters 159 6. 3 Passing values by reference 161 6.4 USing Named Parameters 162 6.5 Enforcing Types of Function Arguments 163 6.6 Creating Functions That Take a Variable Number of Arguments 164 6.7 Returning values by Reference 167 6.8 Returning more Than One value 169 6.9 Skipping Selected Return values 170 6.10 Returning Failure 171 6. 1 1 Calling variable Functions 172 6. 12 Accessing a Global Variable Inside a Function 175 6.13 Creating Dynamic Functions 176 7. Classes and objects.......,.................... 179 7.1 Instantiating Objects 183 7. 2 Defining Object Constructors 184 Table of content 7. 3 Defining object Destructors 185 7.4 Implementing Access Control 186 7.5 Preventing Changes to Classes and Methods 189 7.6 Defining Object Stringification 190 7.7 Requiring Multiple Classes to Behave Similarly 191 7.8 Creating Abstract Base Classes 195 7.9 Assigning Object References 197 7. 10 Cloning Objects 198 7.11 Overriding Property Accesses 201 7. 12 Calling Methods on an Object Returned by Another Method 205 7.13 Aggregating Objects 206 7. 14 Accessing Overridden Methods 210 7. 15 Creating Methods dynamically 212 7.16 Using Method Polymorphism 213 7. 17 Defining Class Constants 215 7. 18 Defining Static Properties and Methods 217 7. 19 Controlling Object Serialization 220 7.20 Introspecting Objects 222 7.21 Checking If an Object Is an Instance of a Specific Class 226 7. 22 Autoloading Class Files upon Object Instantiation 229 7. 23 Instantiating an object dynamically 230 7. 24 Program: whereis 231 8. Web fundamentals ,235 8. 1 Setting Cookies 236 8.2 Reading Cookie Values 8.3 Deleting Cookies 238 8.4 Building a Query String 239 8.5 Reading the POST Request Body 240 8.6 Using Http Basic or Digest Authentication 241 8.7 Using Cookie authentication 245 8.8 Reading an Http Header 248 8.9WritinganhttpHeader 249 8.10 Sending a Specific htTp Status Code 250 8. 11 Redirecting to a Different Location 251 8. 12 Flushing Output to the browser 252 8.13 Buffering Output to the Browser 253 8. 14 Compressing Web Output 255 8.15 Reading Environment Variables 255 8. 16 Setting Environment Variabl 256 8. 17 Communicating Within apache 257 8.18 Redirecting Mobile Browsers to a Mobile Optimized Site 258 ⅵi| Table of contents 8.19 Program: Website Account(De)activator 259 8.20 Program: Tiny Wiki 262 8. 21 Program: Http Range 265 9. Forms 275 9.1 Processing Form Input 277 9.2 Validating Form Input: Required Fields 279 9.3 Validating Form Input: Numbers 281 9.4 Validating Form Input: Email Addresses 283 9.5 Validating Form Input: Drop-Down Menus 284 9.6 Validating Form Input: Radio Buttons 285 9.7 Validating Form Input: Checkboxes 287 9.8 Validating Form Input: Dates and Times 289 9.9 Validating Form Input: Credit Cards 290 9.10 Preventing Cross-Site Scripting 291 9.11 Processing Uploaded Files 292 9 12 Working with Multipage Forms 295 9. 13 Redisplaying Forms with Inline Error Messages 296 9.14 Guarding against Multiple Submissions of the Same Form 299 9. 15 Preventing global Variable Injection 301 9. 16 Handling Remote Variables with Periods in Their Names 303 9. 17 Using Form Elements with Multiple Options 304 9.18 Creating Drop-Down Menus Based on the Current Date 305 10. Database access 307 10.1 USing DBM Databases 310 10.2 USing an SQLite Database 313 10.3 Connecting to an SQL Database 315 10.4 Querying an SQL Database 316 10.5 Retrieving Rows Without a Loop 319 10.6 Modifying Data in an SQL Database 320 10.7 Repeating Queries Efficiently 321 10.8 Finding the Number of Rows returned by a Query 324 10.9 Escaping Quotes 325 10.10 Logging Debugging Information and Errors 327 10.11 Creating Unique Identifiers 329 10.12 Building Queries Programmatically 331 10. 13 Making Paginated Links for a Series of Records 336 10.14 Caching Queries and Results 339 10.15 Accessing a Database Connection Anywhere in Your Program 341 10.16 Program: Storing a Threaded message board 343 Table of Contents 10. 17 Using Redis 351 11. Sessions and data persistence ,353 11.1 USing Session Tracking 354 11.2 Preventing Session Hijacking 356 11.3 Preventing Session Fixation 357 11.4 Storing Sessons in Memcached 358 11.5 Storing Sessions in a Database 359 11.6 Storing Arbitrary Data in Shared Memory 362 11.7 Caching Calculated Results in Summary Tables 365 12. XML ,369 12.1 Generating XML as a String 372 12.2 Generating XML with DOM 373 12.3 Parsing basic XML Documents 376 12.4 Parsing Complex XML Documents 379 12.5 Parsing large xml documents 381 12.6 Extracting Information USing XPath 387 12.7 Transforming XML with XSLT 390 12.8 Setting Xslt Parameters from PHP 392 12.9 Calling php Functions from XSLT Stylesheets 394 12.10 Validating XML Documents 398 12. 11 Handling Content Encoding 400 12 12 Reading RSS and atom Feed 401 12.13 Writing RSS Feeds 404 12 14 Writing Atom Feeds 407 13. Web automation ..................................4...................413 13. 1 Marking up a web page 414 13.2 Cleaning Up Broken or Nonstandard HTML 416 13.3 Extracting Links from an HTML File 420 13.4 Converting Plain Text to HTML 422 13.5 Converting HTML to Plain Text 423 13.6 Removing HTML and PHP Tags 424 13.7 Responding to an Ajax Request 428 13.8 Integrating with JavaScript 429 13.9 Program: Finding Stale Links 433 13.10 Program: Finding Fresh Links 435 14. Consuming reStful APIs 439 14.1 Fetching a URL with the get method 440 14.2 Fetching a URL with the Post Method and Form data 444 I Table of Contents

...展开详情
试读 127P OReilly.PHP.Cookbook.3rd.Edition
立即下载 身份认证VIP会员低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
关注 私信
上传资源赚钱or赚积分
最新推荐
OReilly.PHP.Cookbook.3rd.Edition 9积分/C币 立即下载
1/127
OReilly.PHP.Cookbook.3rd.Edition第1页
OReilly.PHP.Cookbook.3rd.Edition第2页
OReilly.PHP.Cookbook.3rd.Edition第3页
OReilly.PHP.Cookbook.3rd.Edition第4页
OReilly.PHP.Cookbook.3rd.Edition第5页
OReilly.PHP.Cookbook.3rd.Edition第6页
OReilly.PHP.Cookbook.3rd.Edition第7页
OReilly.PHP.Cookbook.3rd.Edition第8页
OReilly.PHP.Cookbook.3rd.Edition第9页
OReilly.PHP.Cookbook.3rd.Edition第10页
OReilly.PHP.Cookbook.3rd.Edition第11页
OReilly.PHP.Cookbook.3rd.Edition第12页
OReilly.PHP.Cookbook.3rd.Edition第13页
OReilly.PHP.Cookbook.3rd.Edition第14页
OReilly.PHP.Cookbook.3rd.Edition第15页
OReilly.PHP.Cookbook.3rd.Edition第16页
OReilly.PHP.Cookbook.3rd.Edition第17页
OReilly.PHP.Cookbook.3rd.Edition第18页
OReilly.PHP.Cookbook.3rd.Edition第19页
OReilly.PHP.Cookbook.3rd.Edition第20页

试读结束, 可继续阅读

9积分/C币 立即下载