This is a short tutorial on how to embed Php code inside HTML code. This is very useful in many situations.
For example if I were to create Php tags and echo out my name here.
By running this , let's click on a file, we just get an Alex.
Now for example, I can embed HTML inside this and echo it out here to make Alex a little bolder.
But what I can do is I can switch this the other way round.
Let's start again, create an HTML page. I'm going to use this example
I will start a Php and a tag here. I echo out Alex and then come in outside the Php tags and add my bold here and my bold end after the ending Php tag
And it gives us the same result, nothing has changed even though I've refreshed the page
So, we can change that to underline and you can see that Alex is underlined.
So, we can do it either ways. It's up to you to use the HTML code inside the echo or not. But there are more uses to this.
Now, if you do know HTML, you know the input tag is a template tag.
So, let's say text and the name of this will be name and the value is going to be equal to Alex
Lets refresh this and we see we've got a text box here with Alex inside.Now I want to use Php to grab the get variable header and put it inside this value of our input value.
Now, this is really useful in some cases like form submission and error checking where you want the posted variables to stay inside the value of each text box.
If you haven't seen the get tutorial already make sure you watch that.
Now, bring this down a couple of lines, obviously we still run this code successfully because it works on similar line basis
So, this you see here is exactly the same as that, you just have to force it down a bit and I'm going to create Php text here
This is going to look a funny brown colour because we're working in Php highlighting and it's not really recognizing this type of highlighting
Ok, I'm just going to echo out Alex
Since this works on a single line basis, bring this all up on a single line. So now I have embed this inside that and your embedding is done.
By refreshing we get the value of Alex. We're echoing out now Php inside a n HTML value
So, we're using Php code inside our value here
I'm going to demonstrate dollar underscore get ,remember using the single quotes
I'm going to say name and then refresh
Nothing's happened so type in name=Alex which gives us Alex inside that
Type in name=Kyle. It gives us Kyle inside that
Basically you can embed any Php code you want inside that
Try saying echo Php info and you'd get a very funny result
This is the HTML code of Php info document
So, you can see that there's loads of code in that
Here we're just working with Php inside.The only thing you need to worry about is being careful with your single and double quotes
So this was the basic tutorial on embedding Php code inside HTML code
I hope it was useful.Thanks for watching
This is Anoushka dubbing for the Spoken tutorials Project