Chapter 4 showed us that you can "slip in and out of HTML made at will using the PHP start and end tags." (125) This chapter showed "you can present distinct output to the user according to a decision-making process you can control with if and switch statements. This example combines the two techniques - it "outputs a table of values only when a variable is set to the Boolean value true." (126) The example is split into multiple echo statements to increase readibility.
NOTICE: The dollar sign, when meant to be interpreted literally, must be escaped with the backslash character. The quotation marks in the style declaration must also be escaped.
| Today's prices in dollars | ||
| $14.00 | $32.00 | $71.00 |
<?php
$display_prices = true;
if ($display_prices) {
echo "<table style=\"border: 1px solid black;\">\n";
echo "<tr><td colspan=\"3\">";
echo "Today's prices in dollars";
echo "</td></tr>";
echo "<tr><td>\$14.00</td><td>\$32.00</td><td>\$71.00</td></tr>\n";
echo "</table>";
}
?>