Monday, December 8, 2008

Chapter 1 in PHP tutorials for dummies - PHP Crash Course

THIS CHAPTER GIVES YOU A QUICK OVERVIEW of PHP syntax and language constructs.If you are already a PHP programmer, it might fill some gaps in your knowledge. If youhave a background using C, Active Server Pages (ASP), or another programming language,it will help you get up to speed quickly.In this book, you’ll learn how to use PHP by working through lots of real-worldexamples taken from our experiences in building e-commerce sites.

Often, programmingtextbooks teach basic syntax with very simple examples.We have chosen not to do that.We recognize that often what you want to do is get something up and running, to understand how the language is used, instead of plowing through yet another syntax and function reference that’s no better than the online manual.Try the examples.Type them in or load them from the CD-ROM, change them,break them, and learn how to fix them again.This chapter begins with the example of an online product order form to show how variables, operators, and expressions are used in PHP.

It also covers variable types and operator precedence.You learn how to access form variables and manipulate them by working out the total and tax on a customer order.You then develop the online order form example by using a PHP script to validate the input data.You examine the concept of Boolean values and look at examples using if, else, the ?: operator, and the switch statement. Finally, you explore looping bywriting some PHP to generate repetitive HTML tables.

Key topics you learn in this chapter include :

1 Embedding PHP in HTML
2 Adding dynamic content
3 Accessing form variables
4 Understanding identifiers
5 Creating user-declared variables
6 Examining variable types
7 Assigning values to variables
8 Declaring and using constants
9 Understanding variable scope
10 Understanding operators and precedence
11 Evaluating expressions
12 Using variable functions
13 Making decisions with if, else, and switch
14 Taking advantage of iteration using while, do, and for loops