Team LiB
Previous Section Next Section

PHP Start and End Tags

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.

Table 4.1: Basic PHP Start and End Tags

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.

  1. Open a new file in your text editor.

  2. Type the following code, which uses the first tag type:

    <?php
    echo "<P>This is a test using the first tag type.</P>";
    ?>
    
  3. Type the following code, which uses the second tag type:

    <?
    echo "<P>This is a test using the second tag type.</P>";
    ?>
    
  4. Type the following code, which uses the third tag type:

    <script language="php">
    echo "<P>This is a test using the third tag type.</P>";
    </script>
    
    
  5. Save the file with the name phptags.php.

  6. Place this file in the document root of your web server.

  7. Open your web browser and type http://127.0.0.1/phptags.php.

    Click To expand
    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.

Click To expand

Team LiB
Previous Section Next Section