Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Dreamweaver gives you the ability to insert simple PHP commands fairly automatically, using either the menu or the Insert panel. For this demonstration, I'll use files in a copy of this site in the folder 02_gettingstarted > 04_insertphpcode. And I'll work with this file, helloworld.php. This file already has a .PHP extension and when I look at it in Live View, which results in copying the file over to my server folder, and browse the file through the localhost URL, I'll see that the file is shown with the simple text "Hello World" in a content area.
I'm going to show you how to replace that literal text with a simple PHP command.
Here is the text inside a pair of
I'm going to remove that text, and then I'm going to use one of the most
fundamental PHP commands,
the echo command, to output a literal string into the browser.
To do this from the menu, select Insert > PHP Objects, and then choose Echo, or if
you prefer, you can use the Insert panel, switch to the PHP category, and then
once again, choose Echo.
I'll click once on the Echo selection. That inserts a PHP code block and adds the echo command. After the Echo command, you can add to the echo command any literal string or any variable or dynamic expression that will evaluate to a string. I'm going to pass in the value Hello World, wrapped in quotes. I'll save my changes and then I'll look at the file again in Live View. I'll exit Live View and then, enter it again. Notice that the file was once again being copied to the testing server, and then I'll go to Design View, and I'll see exactly the same text output.
Now to see this in an external browser, I'll go to the Browser button in the toolbar, and I'll select my favorite browser - I usually use Firefox for testing - go through the copying dialogs, and once again there is the output. Now, here is the important thing to understand about the echo command. I'll look at the Page in the Source View, and here is the text that's being output by the echo command. By the time gets to the browser, it's just text. I'll go back and make a simple change to the code.
I'll go to the Code View, and I'll change the text to Hello World from PHP. I'll browse the page. If prompted, I'll say Yes I want to save the file, and I want to copy it. And now the text is output in the browser, exactly as I typed it in the echo command. And once again, I'll show you Source View and show that that's the text that's output, and that the browser receives simple text. Again, the important thing to understand about PHP and all web application servers is that the commands that you execute that are a part of the server-based language, such as PHP, are executed on the server, and the browser doesn't know anything about them.
The browser receives the resulting HTML markup, including any text that you output.
Get unlimited access to all courses for just $25/month.Become a member