Chapter 2. PHP
In this chapter, we introduce the PHP scripting language. PHP is similar to high-level languages such as C, Perl, Pascal, FORTRAN, and Java, and programmers who have experience with any of these languages should have little trouble learning PHP. This chapter serves as an introduction to PHP; it’s not a programming guide. We assume you are already familiar with programming in a high-level language.
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 theswitch
statementsLooping statements
Arrays and array library functions
Strings and string library functions
Regular expressions
Date and time functions
Integer and float functions
How to write functions, reuse components, and determine the scope and type of variables
An introduction to PHP object-oriented programming support
Common mistakes made by programmers new to PHP, and how to solve them
Programmers new to PHP should read Section 2.1, which describes the basic structure of a PHP script and its relationship to HTML, and includes discussion of how PHP handles variables and types. The two sections that follow, Section 2.2 and Section 2.3, deal with conditional statements and looping structures and should be familiar material. We then present a short example that puts many of the basic PHP concepts together.
The remainder of the chapter expands ...
Get Web Database Applications with PHP, and MySQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.