You are previewing Sams Teach Yourself PHP in 24 Hours, Third Edition.
O'Reilly logo
Sams Teach Yourself PHP in 24 Hours, Third Edition

Book Description

Think of all the things you could do in 24 hours. Go sightseeing. Read a book. Learn PHP. Sams Teach Yourself PHP in 24 Hours is a unique learning tool that is divided into 24 one-hour lessons over five sections. Starting with the basics, you will discover the fundamentals of PHP and how to apply that knowledge to create dynamic websites with forms, cookies and authentication functions. You will also find out how to access databases, as well as how to integrate system components, e-mail, LDAP, network sockets and more. A support website includes access to source code, PHP updates, errata and links to other relevant websites. Sams Teach Yourself PHP in 24 Hours is a quick and easy way to learn how to create interactive websites for your end user.

Table of Contents

  1. Copyright
  2. About the Author
  3. Acknowledgments
  4. Tell Us What You Think!
  5. Introduction
  6. Getting Started
    1. PHP: From Home Page to Web Enterprise
      1. What Is PHP?
      2. What Need Does PHP Fulfill?
      3. What’s New in PHP 5
      4. The Zend Engine
      5. Why Choose PHP?
      6. What’s New in This Edition
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercise
    2. Installing PHP
      1. Platforms, Servers, Databases, and PHP
      2. Where to Find PHP and More
      3. Installing PHP for Linux and Apache
      4. Some configure Options
      5. Configuring Apache
      6. php.ini
      7. Help!
      8. Summary
      9. Q&A
      10. Workshop
      11. Exercise
    3. A First Script
      1. Our First Script
      2. Combining HTML and PHP
      3. Adding Comments to PHP Code
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercise
  7. The Language
    1. The Building Blocks
      1. Variables
      2. Data Types
      3. Operators and Expressions
      4. Constants
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercises
    2. Going with the Flow
      1. Switching Flow
      2. Loops
      3. Code Blocks and Browser Output
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercises
    3. Functions
      1. What Is a Function?
      2. Calling Functions
      3. Defining a Function
      4. Returning Values from User-Defined Functions
      5. Dynamic Function Calls
      6. Variable Scope
      7. Saving State Between Function Calls with the static Statement
      8. More About Arguments
      9. Creating Anonymous Functions
      10. Testing for Function Existence
      11. Summary
      12. Q&A
      13. Workshop
      14. Exercise
    4. Arrays
      1. What Is an Array?
      2. Creating Arrays
      3. Associative Arrays
      4. Multidimensional Arrays
      5. Accessing Arrays
      6. Manipulating Arrays
      7. Sorting Arrays
      8. Functions Revisited
      9. Summary
      10. Q&A
      11. Workshop
      12. Exercises
    5. Working with Strings
      1. Formatting Strings
      2. Investigating Strings
      3. Manipulating Strings
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercises
    6. Objects
      1. What Is an Object?
      2. Creating an Object
      3. Object Properties
      4. Object Methods
      5. Limiting Access to Object Properties
      6. Limiting Access to Object Methods
      7. Constraining Arguments to Methods with Hints
      8. Inheritance
      9. Testing Classes and Objects
      10. Automatically Loading Include Files with ___autoload()
      11. Storing and Retrieving Objects
      12. Summary
      13. Q&A
      14. Workshop
      15. Exercises
  8. Working with PHP
    1. Working with Forms
      1. Superglobal Variables
      2. The $_SERVER Array
      3. A Script to Acquire User Input
      4. Importing User Input into Global Scope
      5. Accessing Form Input with User-Defined Arrays
      6. Combining HTML and PHP Code on a Single Page
      7. Using Hidden Fields to Save State
      8. Redirecting the User
      9. File Upload Forms and Scripts
      10. Summary
      11. Q&A
      12. Workshop
      13. Exercises
    2. Working with Files
      1. Including Files with include()
      2. Using include_once() and include_path to Manage Larger Projects
      3. Testing Files
      4. Creating and Deleting Files
      5. Opening a File for Writing, Reading, or Appending
      6. Reading from Files
      7. Reading the Contents of a File with file_get_contents()
      8. Writing or Appending to a File
      9. Writing Data to a File with file_put_contents()
      10. Working with Directories
      11. Summary
      12. Q&A
      13. Workshop
      14. Exercises
    3. Working with the DBA Functions
      1. Beneath the Abstraction
      2. Opening a Database
      3. Adding Data to the Database
      4. Amending Elements in a Database
      5. Reading from a Database
      6. Determining Whether an Item Exists in a Database
      7. Deleting an Item from a Database
      8. Adding Complex Data Structures to a Database
      9. An Example
      10. Summary
      11. Q&A
      12. Workshop
      13. Exercises
    4. Database Integration—SQL
      1. A (Very) Brief Introduction to SQL
      2. Connecting to the MySQL Database Server
      3. Selecting a Database
      4. Finding Out About Errors
      5. Adding Data to a Table
      6. Acquiring the Value of an Automatically Incremented Field
      7. Accessing Information
      8. Changing Data
      9. SQLite: A Lightweight SQL Engine
      10. Selecting Data
      11. Using the PEAR DB Package
      12. Summary
      13. Q&A
      14. Workshop
      15. Exercises
    5. Beyond the Box
      1. Server Variables Revisited
      2. A Brief Summary of an HTTP Client/Server Negotiation
      3. Getting a Document from a Remote Address
      4. Converting IP Addresses and Hostnames
      5. Making a Network Connection
      6. Sending Mail with the mail() Function
      7. An Introduction to Streams
      8. Summary
      9. Q&A
      10. Workshop
      11. Exercises
    6. Images On-the-Fly
      1. Checking Your Configuration with gd_info()
      2. Creating and Outputting Images
      3. Acquiring Color
      4. Drawing Lines
      5. Applying Color Fills
      6. Drawing an Arc
      7. Drawing a Rectangle
      8. Drawing a Polygon
      9. Making a Color Transparent
      10. Working with Text
      11. Bringing It Together
      12. Summary
      13. Q&A
      14. Workshop
      15. Exercises
    7. Working with Dates and Times
      1. Getting the Date with time()
      2. Converting a Timestamp with getdate()
      3. Converting a Timestamp with date()
      4. Creating Timestamps with mktime()
      5. An Example
      6. A Date Pull-down Library
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercise
    8. Advanced Objects
      1. Objects and Constants
      2. Static Properties
      3. Static Methods
      4. Intercepting Calls to Object Properties and Methods
      5. Final Methods
      6. Cleaning Up Using Destructors
      7. Managing Error Conditions with Exceptions
      8. Tools for Building Object Hierarchies
      9. Passing and Assigning Objects
      10. Summary
      11. Q&A
      12. Workshop
      13. Exercises
    9. Working with Regular Expressions
      1. Perl Compatible Regular Expressions
      2. Summary
      3. Q&A
      4. Workshop
      5. Exercise
    10. Saving State with Cookies and Query Strings
      1. Cookies
      2. Setting a Cookie with PHP
      3. Working with the Query String
      4. Creating a Query String
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercises
    11. Saving State with Session Functions
      1. What Are Session Functions?
      2. Starting a Session with session_start()
      3. Working with Session Variables
      4. Destroying Sessions and Unsetting Elements
      5. Passing Session IDs in the Query String
      6. Encoding and Decoding Session Variables
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
    12. Working with the Server Environment
      1. Opening Pipes to and from Processes with popen() and proc_open()
      2. Running Commands with exec()
      3. Running External Commands with system() or the Backtick Operator
      4. Plugging Security Holes with escapeshellcmd()
      5. Running External Applications with passthru()
      6. Calling an External CGI Script with the virtual() Function
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
    13. XML
      1. What Is XML?
      2. XML Parser Functions
      3. An Introduction to the DOM XML Functions
      4. XSL: A Brief Discussion
      5. Introducing SimpleXML
      6. Summary
      7. Q&A
      8. Workshop
      9. Exercises
  9. Extending PHP
    1. PEAR: Reusable Components to Extend the Power of PHP
      1. What Is PEAR?
      2. Some PEAR Packages in Action
      3. PEAR and Your Own Code
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercises
    2. Toward a Framework for Larger Projects
      1. Principles and Problems
      2. The Controller Object
      3. The RequestHelper and DataStore Classes
      4. The CommandFactory Class
      5. The Command Class
      6. The Dispatcher Class
      7. Working with the Framework
      8. Where Now, and Was It Worth It?
      9. Summary
      10. Q&A
      11. Workshop
      12. Exercises
  10. Glossary
  11. Index