Create and use a PHP variable in the simple page

What we’re doing in this task:

We’re learning about the concept of variables and how they’re used.

We’re learning what variables look like in PHP.

We’re expanding what we know about the echo command (it can use variables).

1. In Dreamweaver, open simple.php and go to Design view.

2. Select the PHP icon.

3. In the Property inspector, change the code to this:

$user = “George”;

echo $user;

(Note that when you’re working in the Property inspector, Dreamweaver doesn’t show you the PHP tags; also, there’s no color coding to help you spot problems.)

4. Go to Code view and make sure your code looks right … and see the color coding.

5. Upload and view the served page; check the source code to see how PHP instructions have been translated into HTML code.

Why did we do this?

We learned what variables are — they are core to the whole PHP scripting functionality.

We learned how to recognize PHP variables in source code (they always start with $).

We learned how to use the Property inspector to view and edit PHP code.