Php Tag

☰ Menu Content


As Php codes can freely mix with Html codes, special tags are needed to seperate them.

All PHP code must be written between a pair of special start tag and end tag

Tag Style

Start Tag

End Tag

Standard tags

<?php

?>

Examples of php tag usage are shown below:-

PHP Code:
<?php
      phpinfo ();
?>

How to Save Your PHP Pages

Web pages that contain Php codes must be saved with .php extension.Then only the server will parse the Php codes.

Example:- A simple HTML & PHP page

Below is an example of a .php file where PHP and HTML codes were written together.

PHP and HTML Code:
<html>
    <head>
        <title>PHP Page</title>
    </head>
    <body>
        <?php
            echo "Hello World!";
        ?>

    </body>
</html>

After saving the above codes as a "helloworld.php" file, place it on a PHP enabled server and view it with your web browser.

You should see "Hello World!" displayed.

Display:
Hello World!

PHP function echo was used to to write "Hello World!" to the browser.

More about this PHP function and many others will be explained later.

The Semicolon!

Every line of Php code must end with a semicolon. It signifies the end of a PHP statement and should never be forgotten.

For example, if we repeated our "Hello World!" code several times, then a semicolon is needed at the end of each statement.

PHP and HTML Code:
<html>
    <head>
        <title>My First PHP Page</title>
    </head>
    <body>
        <?php
            echo "Hello World! ";
            echo "Hello World! ";
            echo "Hello World! ";
            echo "Hello World! ";
            echo "Hello World! ";
        ?>
    </body>
</html>
Display:
Hello World! Hello World! Hello World! Hello World! Hello World!

White Space

Whitespace is ignored between PHP statements.This means it is OK to have one line of PHP code, then 20 lines of blank space before the next line of PHP code. You can also press tab to indent your code and the PHP interpreter will ignore those spaces as well.

PHP and HTML Code:
<html>
    <head>
        <title>My First PHP Page</title>
    </head>
    <body>
            <?php
                echo "Hello World!";








                echo "Hello World!";
            ?>
    </body>
</html>
Display:
Hello World!Hello World!

Note
For more detail please see Php Manual at http://www.php.net

Php Tutorial Content (menu)