6. Embedding PHP in HTML

Share this post on:

Great the time has come for us to start writing some PHP. All right but before we do that let’s go to our root directory.
Make a short cut and put on a desktop because we need to put files there all the time and I don’t want to be traveling from applications or programs whatever operating system you are. I don’t want to be traveling a long way to find this folder. We’ve got to find this for the Right now in Mac.
If you are on a Mac you can find it in your Applications folder and it’s going to be HD docs.
That’s the folder that we’re going to be placing our courses Course Lectures and files all that stuff is going to be right here. Now for Windows users go to you go to your programs go to zap your C drive you should. You should find zap when you find them. I think it’s computer C drive and then zap ending the docs I show you that when we were installing zap. But anyways find that create a shortcut.
I’m going to make an alias because that’s the way you create a shortcut in Mac.
You rightly can create an alias that they name it different needs a whole different animal. Just click it for Windows and create a shortcut and drag it to your desktop.
So now that we have this here we can go ahead and just click it and go straight to our root directory and this is where we’re going to be putting all files.
What I’m going to do right now is I’m just going to open or coeditor just open it up and of course, we’re going to have some files on the full files and I’m going to go back to the dogs here.
I’m going to right-clicking and going to create a new folder called Demel. This is going to be where or if files are going to be right. So we are going to drag this here and now this is going to create worry about that going to create a new project for us here or files are going to be listed right here going down. I’m going to click on this and I’m going to say in bed.
I’m going to make a new file or embed might be a PHP. Now how do we start writing PHP. All right well very simple We have an opening tag LHD a mail-in a closing tag. This is the opening tag for PHP less than symbol question mark and then the keyword PHP this is going to open it up knows an Apache right now.
Whatever you see after this render it as Pietsch be called you know PHP cold here and then when you finish a PHP BE call your command that you need to close that with a semi-colon.
Very important.
Every time you finish a command you need to close you need to let people know that you are done with this command and you might write other commands here. So this is what a semi-colon is. I’m done with this command.
Apache. I’m done with it. That’s what it means. Now this one here is the closing tag for PHP.
So if we don’t have anything here that would be the closing right that usually does what you write it you put it down all the way down and you write your speech be code here and then you put the semi-colon and you’re done.
And then you write some more PHP called down here with a semi-colon semicolon means to stop command right here and then you can write whatever the command after and close the command.
Also, this one closes all the command and right, and then after this goes the mail. So you can insert disengage the mail right now just the way it is. Another thing is that whitespace really doesn’t matter in PHP. You can pull all this in one line. You can bring this all the way down.
You can pull this called here is called here as long as you have a semi-colon there. You’re good to go.
You can put a call like that but of course, we’re not going to do that because it looks bad right. Just to let you in that it really doesn’t matter. I know things that you will see PHP cold reading like this. Leave this there. You will see it. You will see it like this.
That’s a shorthand version and you will see it like this right here.
UCLA is right these other formats that you will see PHP. These are this is that form the reasoning is even. Even though is easier to write like this. Now all computers, not all servers or Apache servers would be this would be turned on them will not be turned on them.
You have to manually go to PHP die and I found to turn this on. So for example let’s say you write a plug-in for president or Drupal. When you become a programmer.
And if you write in this way that people that have a server they have Apache running and they don’t how if they don’t have it turn on. This would not work. This would not work and this would not work. Right, so you cold all of a sudden does now work in many people’s computers or servers or web sites or applications.
It would not work. So this would work everywhere. PHP is available by default. All right it will always work.
So that’s why it is bad form right. That’s one thing there and I wanted to also explain to you that if you have another file here for example the example that a mail and for some reason, you try to put some PHP courting here. It will now work.
You can go ahead and try right now but this would not display. It would not it would now rended PHP sense. This does not have a dot PHP extension. You see a patch looks at this and says you know what this is the amount whatever is in this file is actually a male and not going to even look for PHP.
But when you tell Apache when you put the extensions here that PHP you’re telling Apache that this file here might include some PHP so be on the lookout for PHP Abaci you will see something there. That’s what you’re telling me.
Patchi when you have a PHP extension. So always make sure that you put your that PHP stanching if you want your file to actually work right. So now that we have that how do we look up files right how do we see them on the screen let me write a simple function here or it embedded PHP be here.
And this is called an echo.
This function here is going to print out tests on the screen right now is going to say hello. Student.
And if I can write it and then we close it with a semicolon G’s then we don’t save it. That’s what you’re going to do is going to this is going to Excel. All right he’s going to print something out. We put in double Quarter we can put single quotes. That’s how we write strings right in strings I mean tetes and that’s the term that we use in programming string. And then we close it with a semicolon with close and PHP tags there. So I’m going to click on this little. I can hear. For those that have brackets and as you can see there, we can see that it is.

Hello student,
Now, this might not work for some of you because I already set up mine but I’m going to help you set it up right now if you click this it might give you a window to tell you how to you know to set the base of this right the base directory of this and just close that body and go to file project settings and then he’ll find your setting then put this down.
I’m sorry.
Poor be calling for Slash for Slash local holes. And then the name of your father where your files are going to be and click done and then go ahead and close whatever browser you have on if he’s not working you close it and go ahead and turn this on again.
Turn it on again when you’re is working or if you want to go ahead in it for some reason is not working. Just go to your localhost right here and that’s going to direct you to zap right.
Because he has an issue that’s there. What he’s doing is directing us redirecting us back to this folder. I’m going to take this farther off and going to type in the folder name and I click enter in as you can see here this is the end of them. And here we’ve got two files. The embed that PHP and that example that HDMI is going to show you the example.
There is nothing there and we have some PHP there but if it doesn’t work well let’s just put a function here real quick just to show you hello. There we go.
And the FI refresh doesn’t work.
Let me show you if I right-click on it this is Google Chrome by the way if I click on this and choose View Source we can see that ph be there but he’s now rendering.
Let’s put some NHT of mail here and you’re going to put an H-1 tag.
And no. All right refresh and we can see that that’s work. Let’s take this view source.
Let’s open this in let’s go to the demo there and go to the example the mountain we can see the H-1.
But if we click on it and we check on view source we can see that it should be there but he’s now working so it doesn’t work with the Deitsch the mail.
Make sure you have that PHP in there. Another thing I want you to install if you use in brackets is an extension called Emma. And this is really really easy to install.
Go to your File tab here click on extension manager. Here we can still many different plugins for exactly for this coeditor and type in e m d t Emmett. I already have it in stores so this is going to be great out.
But you’re going to have a little button like this here.
Is going to sing stole just clicking any will store this automatically.
The reason why I want you to install that is that it’s going to make you a better programmer.
Let me tell you why you got to be a lot more productive when you actually use this.
Now that you have it installed right.
I want you to put an exclamation there with a shift key and you press number one on your keyboard. And then after the exclamation there you put your cursor here and you press on the tab.  Look at that.
We roll all this code just by doing that. And we can do many different things with it.
So that’s one of the reasons I want you to do that. So let’s say for example I have something here. Class what to do with a class and them more than one and put you well there and then you show you the power of this.
You might think we’re in there was he doing. Well, look at this. This is the type of thing that we will do. Now I won’t do this all the time sense and if I do. For those of you that don’t have this code or I will wait for you.
All right so I will wait for you to write this and I will go slowly so don’t worry about my writing code too fast.
I just want my students that downloaded brackets to know that this is available to them if they want to. Anyway, thank you so much for watching this video here. Let’s go to the next lecture. I want to show you some more PHP.

 

Code for includeing PHP in HTML

 

<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title></title>
</head>
<body>
<?php
// put your code here
?>
</body>
</html>

Share this post on:

Leave a Reply