Put a PHP command into the simple page

What we’re doing in this task:

We’re seeing how PHP instructions work within the HTML structure of a page, and how to embed the PHP code.

We’re also learning another very simple PHP command: echo

1. Change the file extension of simple.html to simple.php

(Windows users: it’s important that your computer show file extensions, so you can see exactly what type of file you’re dealing with.)

2. Open simple.php.

3. Go to Code view.

4. Change the body code to look like this (new code is in boldface):

<h1>Welcome to My Simple Page!</h1>

<?php

echo “Hello from PHP”;

?>

5. Look at the page in Design view.

The PHP icon shows where the PHP code is.

6. Select the icon, and the Property inspector shows you what’s inside the PHP tags. (You can edit it from here if you want.)

7. Preview in browser (local); you won’t see the dynamic content properly.

8. Upload and preview the served page.

You see the hello message on the page.

9. In the browser, view source. Note how the PHP code has been stripped out and replaced.

(That’s part of the whole HTTP request process.)

Why did we do this?

To see how PHP and HTML code work together, and how they are processed together.

To see what PHP code looks like in Design view.

To learn about the echo command. This command is used a lot. It’s how PHP puts information into the HTML page.