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

From Script | Spoken-Tutorial
Revision as of 12:11, 29 November 2012 by Chandrika (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
0:0 This is a short tutorial on how to embed Php code inside HTML code. This is very useful in many situations.
0:14 For example if I were to create Php tags and echo out my name here.
0:24 By running this , let's click on a file, we just get an Alex.
0:30 Now for example, I can embed HTML inside this and echo it out here to make Alex a little bolder.
0:42 But what I can do is I can switch this the other way round.
0:46 Let's start again, create an HTML page. I'm going to use this example
0:53 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
01:14 And it gives us the same result, nothing has changed even though I've refreshed the page
01:18 So, we can change that to underline and you can see that Alex is underlined.
01:28 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:51 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 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.
02:16 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:34 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:49 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:57 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:04 Ok, I'm just going to echo out Alex
03:11 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.
03:24 By refreshing we get the value of Alex. We're echoing out now Php inside a n HTML value
03:35 So, we're using Php code inside our value here
03:41 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's 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:09 Basically you can embed any Php code you want inside that
04:14 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:36 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:48 So this was the basic tutorial on embedding Php code inside HTML code
04:54 I hope it was useful.Thanks for watching
05:00 This is Anoushka dubbing for the Spoken tutorials Project

Contributors and Content Editors

Chandrika