2.2. HTML Embedding

The first thing you need to learn about PHP is how it is embedded in HTML:

<HTML>
<HEAD>Sample PHP Script</HEAD>
<BODY>
The following prints "Hello, World":
<?php

    print "Hello, World";

?>
</BODY>
</HTML>

In this example, you see that your PHP code sits embedded in your HTML. Every time the PHP interpreter reaches a PHP open tag <?php, it runs the enclosed code up to the delimiting ?> marker. PHP then replaces that PHP code with its output (if there is any) while any non-PHP text (such as HTML) is passed through as-is to the web client. Thus, running the mentioned script would lead to the following output:

<HTML>
<HEAD>Sample PHP Script</HEAD>
<BODY>
The following prints "Hello, World":
Hello, World
</BODY>
</HTML>

Tip ...

Get PHP 5 Power Programming 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.