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>
You may also use a shorter <? as the PHP open tag if you enable the short_open_tags INI option; however, this usage is not recommended and is therefore off by default.
Because the next three chapters deal with language features, the examples are usually not enclosed inside PHP open and close tags. If you want to run them successfully, you need to add them by yourself.