Code Blocks and Browser Output

In Hour 3, “A First Script,” we established that you can slip in and out of HTML mode at will, using the PHP start and end tags. In this chapter you have discovered that you can present distinct output to the user according to a decision-making process you can control with if and switch statements. In this section, we will combine these two techniques.

Imagine a script that outputs a table of values only when a variable is set to the Boolean value true. Listing 5.13 shows a simplified HTML table constructed with the code block of an if statement.

Listing 5.13. A Code Block Containing Multiple print() Statements
 1: <!DOCTYPE html PUBLIC 2: "-//W3C//DTD XHTML 1.0 Strict//EN" 3: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition 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.