Who This Book Is For
This book is aimed at those who want to learn PHP, even if they don't have any previous programming or scripting experience. You can even use this book to learn PHP as a first programming language if you do not have any previous experience.
If you have some previous programming experience but have not written for the web before, you can use this book to learn about the PHP language and how to apply programming techniques to the web environment.
This book does not teach you HTML. Although knowledge of HTML is not a prerequisite, having published web pages in the past will be an advantageeven if you do not usually hand-code HTML.
How This Book Is Organized
This book is organized into five parts.
Part I: PHP Foundations
The lessons in Part I introduce the basic building blocks of the PHP language:
Lesson 1: Getting to Know PHP. This chapter introduces you to what PHP is all about and gives some simple examples to show how PHP is used inside a web page.
Lesson 2: Variables. This chapter explains how you assign values to variables and demonstrates some simple expressions.
Lesson 3: Flow Control. This chapter examines the conditional and looping constructs that allow you to control the flow of a PHP script.
Lesson 4: Functions. This chapter explains how you can modularize and reuse a frequently used section of code as a function.
Part II: Working with Data
The lessons in Part II examine in more detail the different types of data that can be manipulated by PHP:
Lesson 5: Working with Numbers. This chapter gives more detailed examples of the numeric manipulation you can perform in PHP.
Lesson 6: Working with Strings. This chapter examines the powerful set of string functions that PHP provides.
Lesson 7: Working with Arrays. This chapter explains how arrays work and examines the PHP functions that can manipulate this powerful data type.
Lesson 8: Regular Expressions. This chapter shows how to perform complex string manipulation by using powerful regular expressions.
Lesson 9: Working with Dates and Times. This chapter examines how to use date and time values in a PHP script.
Lesson 10: Using Classes. This chapter introduces you to object-oriented PHP and examines how you define and access a class in a script.
Part III: The Web Environment
The lessons in Part III deal with using PHP specifically in the web environment:
Lesson 11: Processing HTML Forms. This chapter shows how you use PHP to process user-submitted input from an HTML form.
Lesson 12: Generating Dynamic HTML. This chapter examines some techniques for creating HTML components on-the-fly from PHP.
Lesson 13: Form Validation. This chapter examines some techniques for validating user-submitted input from an HTML form.
Lesson 14: Cookies and Sessions. This chapter shows how to pass data between pages by using PHP sessions and how to send cookies to a user's browser.
Lesson 15: User Authentication. This chapter examines some techniques for validating user-submitted input from an HTML form.
Lesson 16: Communicating with the Web Server. This chapter looks at ways in which PHP can interact with a web server.
Part IV: Using Other Services from PHP
Part IV looks at how PHP can communicate with external programs and services:
Lesson 17: Filesystem Access. This chapter examines the PHP functions that enable you to access the filesystem.
Lesson 18: Host Program Execution. This chapter examines the PHP functions that enable you to execute programs on the host system.
Lesson 19: Using a MySQL Database. This chapter shows how to use a MySQL database for data storage and retrieval from PHP.
Lesson 20: Database Abstraction. This chapter explains how you can access a database through an abstraction layer to make scripts more portable.
Lesson 21: Running PHP on the Command Line. This chapter shows how you can use PHP as a powerful shell scripting language.
Lesson 22: Error Handling and Debugging. This chapter discusses some techniques for finding and fixing bugs in scripts.
Part V: Configuring and Extending PHP
The final part of the book deals with PHP administration:
Lesson 23: PHP Configuration. This chapter explains some of the popular configuration options that can be set at runtime to change the behavior of PHP.
Lesson 24: PHP Security. This chapter discusses security issues in PHP scripts and shows how you can use Safe Mode on a shared web server.
Lesson 25: Using PEAR. This chapter introduces the freely available classes that are available in the PHP Extension and Application Repository.
Versions of Software Covered
At the time of writing, the current version of PHP is PHP 5.0.3. Unless otherwise stated, all code examples in this book will work with PHP 4.1.0 and higher.
Conventions Used in This Book
This book uses different typefaces to differentiate between code and regular English, and also to help you identify important concepts.
Text that you type and text that should appear on your screen is presented in monospace type.
It will look like this to mimic the way text looks on your screen.
Placeholders for variables and expressions appear in monospace italic font. You should replace the placeholder with the specific value it represents.
A Note presents interesting pieces of information related to the surroundingdiscussion.
A Tip offers advice or teaches an easier way to do something.
A Caution advises you about potential problems and helps you steer clear ofdisaster.