Chapter 2. The PHP Scripting Language

This chapter is the first of three that focus on the PHP scripting language. This chapter describes the PHP language basics. Chapter 3 describes PHP’s support for arrays, strings, and other data types, and Chapter 4 introduces object-oriented programming in PHP.

If you’re familiar with any programming language, PHP should be easy to learn. If you have done no programming before, the pace of this chapter may be brisk but should still be manageable. PHP has a syntax similar to JavaScript, which many web designers have learned; both languages hark back to the classic C and Perl languages in syntax.

The topics covered in this chapter include:

  • PHP basics, including script structure, variables, supported types, constants, expressions, and type conversions

  • Condition and branch statements supported by PHP, including if, if...else, and the switch statements

  • Looping statements

  • User-defined functions

We conclude the chapter with a short example that puts many of the basic PHP concepts together.

Introducing PHP

The current version of PHP is PHP4 (Version 4.3.4). PHP5 is available for beta testing at the time of writing as Version 5.0.0b3. We discuss both versions in this chapter.

PHP is a recursive acronym that stands for PHP: Hypertext Preprocessor; this is in the naming style of GNU, which stands for GNU’s Not Unix and which began this odd trend. The name isn’t a particularly good description of what PHP is and what it’s commonly used for. PHP is a scripting language ...

Get Web Database Applications with PHP and MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.