Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
I now have a page called Creative Variables, and this page was built in the Create Variables movie, and what we want to do is display information on the page. So right now, if I put this in the browser, nothing is displayed. The space is created in computer memory. Those values are stored. Now, how do we get them onto the page? Well, what were going to do is use a command in PHP that tells PHP to write to the page and that command is Echo.
And what I'm going to do is say Echo, dollar, hello. Now, notice in my code hints that pop-up because I created this variable up here, Dreamweaver understands that variable has been created. This is another, new CS5 and 5.5 feature. And I can work with it that way. I'm also going to say dollar sign world. Once it's showing, I hit Enter or Return, add my semicolon, and that should display our information.
Let's check it out. Now, this is saying there's a syntax error on our page, so let's take a look at what it does in the browser. And you can see, there is definitely a syntax error in our code, and these are not the easiest to understand in terms of what it is PHP wants you to do. However, you can kinda start reading some of these. It looks like it's expecting something. Well, we know that there's a semicolon at the end of the line. What's wrong with this piece is the quote feature.
Let's see what happens if we add double quotes. And now it says, no syntax error. So, even though, it's a variable. We still, in order for PHP to be happy, we must put anything after Echo inside of double quotes and you can see my name is being printed. Now, what if I want to change these values? I don't want it to be my specific name, I want it to say, Hello World, once again.
I'll change the value. The value is on the right-side of the equal sign. So this is the information that goes inside that drawer is going to change. But I don't need to change this line in order to do that. So I'll Preview. Now, it says Hello World. So the value is being displayed whatever the value is at that point in time. And that's the basis of all variables in any type of language. Be it client-side language, server-side language, programming language or scripting language.
A variable exists in all of those, so anytime you want to display a variable Echo is what you tell PHP. Now, we used the code block here in the PHP tab to create the code block. Let me show you another feature Dreamweaver has. And I'm going to put it into a separate code block, because I want to show you this complete piece. Just to the right of the code block is Echo, but when you use Echo, it prints out the opening and closing PHP code block plus it says Echo.
And when you go to do this, I click withed my cursor. Let me show you. See how the cursor is right in the spot where you can start typing. So this Echo is a little bit more complete. If you need to output information to the page, this adds the code block and the word Echo and adds the space. So, all you have to do is click that, and start typing what you want to put in here. Now, get rid of those, you can see the red error. It isn't happy, because there's a word, Echo, and just like up here, we don't have the double quotes on each side of what we want to display.
So that is how you display a variables in PHP. Now, that concept transfers whether I want to display it in a table, whether I want to just split it in the middle of a sentence. It doesn't matter. In the middle of a form field. Echo is how you tell PHP print this out to the page. You can think of it like printing it as HTML. So that is displaying a variable in PHP.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97456 Viewers
61 Video lessons · 84687 Viewers
71 Video lessons · 68887 Viewers
56 Video lessons · 101331 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.