Combining HTML and PHP

The code in Listing 3.1 and Listing 3.2 is pure PHP. You can incorporate this into an HTML document simply by adding HTML outside the PHP start and end tags, as shown in Listing 3.3.

Listing 3.3. A PHP Script Including HTML
 1: <!DOCTYPE html PUBLIC
 2:   "-//W3C//DTD XHTML 1.0 Strict//EN"
 3: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 4: <html>
 5: <head>
 6: <title>Listing 3.2 A PHP Script Including HTML</title>
 7: </head>
 8: <body>
 9: <div><b>
10: <?php
11: print "hello world";
12: ?>
13: </b></div>
14: </body>
15: </html>

As new devices access the Web running new browsers on ever more platforms, standards are becoming ...

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.