Learning PHP 5

Book description

PHP has gained a following among non-technical web designers who need to add interactive aspects to their sites. Offering a gentle learning curve, PHP is an accessible yet powerful language for creating dynamic web pages. As its popularity has grown, PHP's basic feature set has become increasingly more sophisticated. Now PHP 5 boasts advanced features--such as new object-oriented capabilities and support for XML and Web Services--that will please even the most experienced web professionals while still remaining user-friendly enough for those with a lower tolerance for technical jargon.If you've wanted to try your hand at PHP but haven't known where to start, then Learning PHP 5 is the book you need. If you've wanted to try your hand at PHP but haven't known where to start, then Learning PHP 5 is the book you need. With attention to both PHP 4 and the new PHP version 5, it provides everything from a explanation of how PHP works with your web server and web browser to the ins and outs of working with databases and HTML forms. Written by the co-author of the popular PHP Cookbook, this book is for intelligent (but not necessarily highly-technical) readers. Learning PHP 5 guides you through every aspect of the language you'll need to master for professional web programming results. This book provides a hands-on learning experience complete with exercises to make sure the lessons stick.Learning PHP 5 covers the following topics, and more:

  • How PHP works with your web browser and web server
  • PHP language basics, including data, variables, logic and looping
  • Working with arrays and functions
  • Making web forms
  • Working with databases like MySQL
  • Remembering users with sessions
  • Parsing and generating XML
  • Debugging
Written by David Sklar, coauthor of the PHP Cookbook and an instructor in PHP, this book offers the ideal classroom learning experience whether you're in a classroom or on your own. From learning how to install PHP to designing database-backed web applications, Learning PHP 5 will guide you through every aspect of the language you'll need to master to achieve professional web programming results.

Publisher resources

View/Submit Errata

Table of contents

  1. Dedication
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Who This Book Is For
    2. Contents of This Book
    3. Other Resources
    4. Conventions Used in This Book
      1. Programming Conventions
      2. Typographical Conventions
    5. Using Code Examples
    6. Comments and Questions
    7. Acknowledgments
  4. 1. Orientation and First Steps
    1. 1.1. PHP’s Place in the Web World
    2. 1.2. What’s So Great About PHP?
      1. 1.2.1. PHP Is Free (as in Money)
      2. 1.2.2. PHP Is Free (as in Speech)
      3. 1.2.3. PHP Is Cross-Platform
      4. 1.2.4. PHP Is Widely Used
      5. 1.2.5. PHP Hides Its Complexity
      6. 1.2.6. PHP Is Built for Web Programming
    3. 1.3. PHP in Action
    4. 1.4. Basic Rules of PHP Programs
      1. 1.4.1. Start and End Tags
      2. 1.4.2. Whitespace and Case-Sensitivity
      3. 1.4.3. Comments
    5. 1.5. Chapter Summary
  5. 2. Working with Text and Numbers
    1. 2.1. Text
      1. 2.1.1. Defining Text Strings
      2. 2.1.2. Manipulating Text
        1. 2.1.2.1. Validating strings
        2. 2.1.2.2. Formatting text
    2. 2.2. Numbers
      1. 2.2.1. Using Different Kinds of Numbers
      2. 2.2.2. Arithmetic Operators
    3. 2.3. Variables
      1. 2.3.1. Operating on Variables
      2. 2.3.2. Putting Variables Inside Strings
    4. 2.4. Chapter Summary
    5. 2.5. Exercises
  6. 3. Making Decisions and Repeating Yourself
    1. 3.1. Understanding true and false
    2. 3.2. Making Decisions
    3. 3.3. Building Complicated Decisions
    4. 3.4. Repeating Yourself
    5. 3.5. Chapter Summary
    6. 3.6. Exercises
  7. 4. Working with Arrays
    1. 4.1. Array Basics
      1. 4.1.1. Creating an Array
      2. 4.1.2. Choosing a Good Array Name
      3. 4.1.3. Creating a Numeric Array
      4. 4.1.4. Finding the Size of an Array
    2. 4.2. Looping Through Arrays
    3. 4.3. Modifying Arrays
    4. 4.4. Sorting Arrays
    5. 4.5. Using Multidimensional Arrays
    6. 4.6. Chapter Summary
    7. 4.7. Exercises
  8. 5. Functions
    1. 5.1. Declaring and Calling Functions
    2. 5.2. Passing Arguments to Functions
    3. 5.3. Returning Values from Functions
    4. 5.4. Understanding Variable Scope
    5. 5.5. Chapter Summary
    6. 5.6. Exercises
  9. 6. Making Web Forms
    1. 6.1. Useful Server Variables
    2. 6.2. Accessing Form Parameters
    3. 6.3. Form Processing with Functions
    4. 6.4. Validating Data
      1. 6.4.1. Required Elements
      2. 6.4.2. Numeric or String Elements
      3. 6.4.3. Number Ranges
      4. 6.4.4. Email Addresses
      5. 6.4.5. <select> Menus
      6. 6.4.6. HTML and JavaScript
      7. 6.4.7. Beyond Syntax
    5. 6.5. Displaying Default Values
    6. 6.6. Putting It All Together
    7. 6.7. Chapter Summary
    8. 6.8. Exercises
  10. 7. Storing Information with Databases
    1. 7.1. Organizing Data in a Database
    2. 7.2. Connecting to a Database Program
    3. 7.3. Creating a Table
    4. 7.4. Putting Data into the Database
    5. 7.5. Inserting Form Data Safely
    6. 7.6. Generating Unique IDs
    7. 7.7. A Complete Data Insertion Form
    8. 7.8. Retrieving Data from the Database
    9. 7.9. Changing the Format of Retrieved Rows
    10. 7.10. Retrieving Form Data Safely
    11. 7.11. A Complete Data Retrieval Form
    12. 7.12. MySQL Without PEAR DB
    13. 7.13. Chapter Summary
    14. 7.14. Exercises
  11. 8. Remembering Users with Cookies and Sessions
    1. 8.1. Working with Cookies
    2. 8.2. Activating Sessions
    3. 8.3. Storing and Retrieving Information
    4. 8.4. Configuring Sessions
    5. 8.5. Login and User Identification
    6. 8.6. Why setcookie( ) and session_start( ) Want to Be at the Top of the Page
    7. 8.7. Chapter Summary
    8. 8.8. Exercises
  12. 9. Handling Dates and Times
    1. 9.1. Displaying the Date or Time
    2. 9.2. Parsing a Date or Time
    3. 9.3. Dates and Times in Forms
      1. 9.3.1. A Single Menu with One Choice Per Day
      2. 9.3.2. Multiple Menus for Month, Day, and Year
      3. 9.3.3. Multiple Menus for Hour and Minute
      4. 9.3.4. Processing Date and Time <select> Menus
    4. 9.4. Displaying a Calendar
    5. 9.5. Chapter Summary
    6. 9.6. Exercises
  13. 10. Working with Files
    1. 10.1. Understanding File Permissions
    2. 10.2. Reading and Writing Entire Files
      1. 10.2.1. Reading a File
      2. 10.2.2. Writing a File
    3. 10.3. Reading and Writing Parts of Files
    4. 10.4. Working with CSV Files
    5. 10.5. Inspecting File Permissions
    6. 10.6. Checking for Errors
    7. 10.7. Sanitizing Externally Supplied Filenames
    8. 10.8. Chapter Summary
    9. 10.9. Exercises
  14. 11. Parsing and Generating XML
    1. 11.1. Parsing an XML Document
    2. 11.2. Generating an XML Document
    3. 11.3. Chapter Summary
    4. 11.4. Exercises
  15. 12. Debugging
    1. 12.1. Controlling Where Errors Appear
    2. 12.2. Fixing Parse Errors
    3. 12.3. Inspecting Program Data
    4. 12.4. Fixing Database Errors
    5. 12.5. Chapter Summary
    6. 12.6. Exercises
  16. 13. What Else Can You Do with PHP?
    1. 13.1. Graphics
    2. 13.2. PDF
    3. 13.3. Shockwave/Flash
    4. 13.4. Browser-Specific Code
    5. 13.5. Sending and Receiving Mail
    6. 13.6. Uploading Files in Forms
    7. 13.7. The HTML_QuickForm Form-Handling Framework
    8. 13.8. Classes and Objects
      1. 13.8.1. Object Basics
      2. 13.8.2. Creating a New Object
      3. 13.8.3. Accessing Properties and Methods
    9. 13.9. Advanced XML Processing
    10. 13.10. SQLite
    11. 13.11. Running Shell Commands
    12. 13.12. Advanced Math
    13. 13.13. Encryption
    14. 13.14. Talking to Other Languages
    15. 13.15. IMAP, POP3, and NNTP
    16. 13.16. Command-Line PHP
    17. 13.17. PHP-GTK
    18. 13.18. Even More Things You Can Do with PHP
  17. A. Installing and Configuring the PHP Interpreter
    1. A.1. Using PHP with a Web-Hosting Provider
    2. A.2. Installing the PHP Interpreter
      1. A.2.1. Installing on Windows
        1. A.2.1.1. Installing PHP
        2. A.2.1.2. EasyPHP
      2. A.2.2. Installing on Linux and Unix
      3. A.2.3. Installing on OS X
    3. A.3. Installing PEAR
    4. A.4. Downloading and Installing PHP’s Friends
      1. A.4.1. Installing Apache
        1. A.4.1.1. Apache on Windows
        2. A.4.1.2. Apache on OS X
        3. A.4.1.3. Apache on Linux
      2. A.4.2. MySQL
    5. A.5. Modifying PHP Configuration Directives
    6. A.6. Appendix Summary
  18. B. Regular Expression Basics
    1. B.1. Characters and Metacharacters
    2. B.2. Quantifiers
    3. B.3. Anchors
    4. B.4. Character Classes
    5. B.5. Greed
    6. B.6. PHP’s PCRE Functions
      1. B.6.1. Matching
      2. B.6.2. Replacing
      3. B.6.3. Array Processing
    7. B.7. Appendix Summary
    8. B.8. Exercises
  19. C. Answers To Exercises
    1. C.1. Chapter 2
      1. C.1.1. Exercise 1:
      2. C.1.2. Exercise 2:
      3. C.1.3. Exercise 3:
      4. C.1.4. Exercise 4:
      5. C.1.5. Exercise 5:
    2. C.2. Chapter 3
      1. C.2.1. Exercise 1:
      2. C.2.2. Exercise 2:
      3. C.2.3. Exercise 3:
      4. C.2.4. Exercise 4:
    3. C.3. Chapter 4
      1. C.3.1. Exercise 1:
      2. C.3.2. Exercise 2:
      3. C.3.3. Exercise 3:
      4. C.3.4. Exercise 4:
    4. C.4. Chapter 5
      1. C.4.1. Exercise 1:
      2. C.4.2. Exercise 2:
      3. C.4.3. Exercise 3:
      4. C.4.4. Exercise 4:
    5. C.5. Chapter 6
      1. C.5.1. Exercise 1:
      2. C.5.2. Exercise 2:
      3. C.5.3. Exercise 3:
      4. C.5.4. Exercise 4:
      5. C.5.5. Exercise 5:
    6. C.6. Chapter 7
      1. C.6.1. Exercise 1:
      2. C.6.2. Exercise 2:
      3. C.6.3. Exercise 3:
      4. C.6.4. Exercise 4:
    7. C.7. Chapter 8
      1. C.7.1. Exercise 1:
      2. C.7.2. Exercise 2:
      3. C.7.3. Exercise 3:
      4. C.7.4. Exercise 4:
    8. C.8. Chapter 9
      1. C.8.1. Exercise 1:
      2. C.8.2. Exercise 2:
      3. C.8.3. Exercise 3:
      4. C.8.4. Exercise 4:
    9. C.9. Chapter 10
      1. C.9.1. Exercise 1:
      2. C.9.2. Exercise 2:
      3. C.9.3. Exercise 3:
      4. C.9.4. Exercise 4:
      5. C.9.5. Exercise 5:
    10. C.10. Chapter 11
      1. C.10.1. Exercise 1:
      2. C.10.2. Exercise 2:
      3. C.10.3. Exercise 3:
      4. C.10.4. Exercise 4:
    11. C.11. Chapter 12
      1. C.11.1. Exercise 1:
      2. C.11.2. Exercise 2:
      3. C.11.3. Exercise 3:
      4. C.11.4. Exercise 4:
    12. C.12. Appendix B
      1. C.12.1. Exercise 1:
      2. C.12.2. Exercise 2:
      3. C.12.3. Exercise 3:
      4. C.12.4. Exercise 4:
  20. Index
  21. About the Author
  22. Colophon
  23. Copyright

Product information

  • Title: Learning PHP 5
  • Author(s): David Sklar
  • Release date: June 2004
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596005603