PHP-and-MySQL/C2/Embedding-PHP/English-timed

From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
00:00 This is a short tutorial on how to embed Php code inside HTML code. This is very useful in many situations.
00:14 For example, if I were to create Php tags and echo out my name here.
00:23 By running this, let's click on a file, we just get "Alex".
00:30 Now for example, I can embed HTML inside this and echo it out here to make "Alex" a little bolder.
00:38 But what I can do is I can switch this the other way round.
00:45 Let's start again, create an HTML page. I'm going to use this example.
00:52 I will start a Php and a tag here. I echo out "Alex" and then coming outside the Php tags and add my bold() here and my bold end() after the ending Php tag.
01:13 And it gives us the same result, nothing has changed even though I've refreshed the page.
01:20 So, we can change that to underline and you can see that "Alex" is underlined.
01:26 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.
01:39 Now, if you do know HTML, you know the input tag is a template tag.
01:48 So, let's say 'text' and the name of this will be 'name' and the value is going to be equal to 'Alex'.
01:56 Let's 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.
02:14 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.
02:30 If you haven't seen the GET tutorial already, make sure you watch that.
02:38 Now, bring this down a couple of lines, obviously we still run this code successfully because it works on similar line basis.
02:48 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.
02:58 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.
03:08 Ok, I'm just going to echo out "Alex".
03:12 Since this works on a single line basis, bring this all up on a single line. So, now I have embedded this inside that and your embedding is done.
03:25 By refreshing we get the value of "Alex". We're echoing out now Php inside an HTML value.
03:35 So, we're using Php code inside our value here.
03:40 I'm going to demonstrate dollar ($) underscore (_) GET, remember using the single quotes.
03:50 I'm going to say 'name' and then refresh.
03:55 Nothing has happened; so type in name=alex which gives us "alex" inside that.
04:04 Type in name=kyle. It gives us "kyle" inside that.
04:11 Basically you can embed any Php code you want inside that.
04:16 Try saying echo Php info() and you'd get a very funny result.
04:28 This is the HTML code of Php info document.
04:33 So, you can see that there's loads of code in that.
04:37 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.
04:46 So this was the basic tutorial on embedding Php code inside HTML code.
04:53 I hope it was useful. Thanks for watching.
04:56 This is Anoushka, dubbing for the Spoken tutorials Project.

Contributors and Content Editors

Minal, PoojaMoolya, Pratik kamble, Sandhya.np14