The PHP parser recognizes a few types of PHP start and end tags. It will attempt to execute anything between these tags, so it had better be valid code!
Study Table 4.1 to learn the three main sets of start and end tags recognized by the PHP parser.
|
Opening Tag |
Closing Tag |
|---|---|
|
<?php |
?> |
|
<? |
?> |
|
<script language="php"> |
</script> |
Next, you'll use all three sets of tags in a script, which I promise will execute without errors.
Open a new file in your text editor.
Type the following code, which uses the first tag type:
<?php echo "<P>This is a test using the first tag type.</P>"; ?>
Type the following code, which uses the second tag type:
<? echo "<P>This is a test using the second tag type.</P>"; ?>
Type the following code, which uses the third tag type:
Save the file with the name phptags.php.
Place this file in the document root of your web server.
Open your web browser and type http://127.0.0.1/phptags.php.
| Note |
While executing the examples in this book, if you are using PHP on an external web server, substitute that server's domain name for the 127.0.0.1 address in the URL. |
In your web browser, you should see the results of your script.
In the next section, you'll learn that putting PHP blocks inside HTML is not a scary thing.