Prev | Current Page 130 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


56 CHAPTER 3 ?–  PHP B ASICS
?– Note This chapter simultaneously serves as both a tutorial for novice programmers and a reference
for experienced programmers who are new to the PHP language. If you fall into the former category,
consider reading the chapter in its entirety and following along with the examples.
Embedding PHP Code in Your Web Pages
One of PHP??™s advantages is that you can embed PHP code directly alongside HTML.
For the code to do anything, the page must be passed to the PHP engine for interpretation.
But the Web server doesn??™t just pass every page; rather, it passes only those pages
identified by a specific file extension (typically .php) as configured per the instructions in
Chapter 2. But even selectively passing only certain pages to the engine would nonetheless
be highly inefficient for the engine to consider every line as a potential PHP
command. Therefore, the engine needs some means to immediately determine which
areas of the page are PHP-enabled. This is logically accomplished by delimiting the PHP
code. There are four delimitation variants, all of which are introduced in this section.
Default Syntax
The default delimiter syntax opens with , like this:

Welcome!


echo "

Some dynamic output here

";
?>

Some static output here


If you save this code as test.php and execute it from a PHP-enabled Web server,
you??™ll see the output shown in Figure 3-1.


Pages:
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142