Screen Printing

TUTORIALS » PHP / MySQL » PHP essentials (guided tutorials)

Starting with PHP

Page 2 of 2


You are in page:
» 2. Sending HTML code using echo

Sending HTML code using echo

Maybe you already noticed it in the last exercise; the strings (text) you send to the browser using PHP can contain HTML tags. These tags will be processed by the browser as if they were contained in any regular .html file.

Complete the next exercise and see it for yourself.

  1. Create a new .php file (text file) and name it echowithtags.php
  2. Write the following code inside:
    <?php
     echo '<h1>This is a HTML title</h1>
           and this is an <i>italic</i> word.
           <hr />
           <b>Yeah!</b>';
    ?>
    Notice that even when I'm splitting my string in four lines, PHP still sees it as a single line of instruction; it begins with the command
    echo
    and ends with a semicolon. Sometimes it is convenient to split-and-arrange instruction lines this way for clarity purposes.
  3. Upload your file to the exercises folder of your server and test it with your browser (remember, you have to write the full path to your file in the URL address bar).
Q. What do you see on screen?

Q. What is the source code of the page displayed by your browser?

You just sent four lines of HTML code using PHP from your server and your browser took it as if it were a regular .html file.

PHP is so cool!

Now you are ready for the next tutorial – Comments in PHP.

More pages of this tutorial → Starting with PHP  <12

Comments & Questions