How To Template In Php #1

How To Template In Php #1 Video

How To Template In Php #1 Video Transcript

hi in this video I’ll show you how to template with PHP when I mean by template in with PHP I mean to separate the HTML files from the PHP files so here with me I have two documents which I have contended HTML and I also have a template dot PHP so when i refresh the template with PHP like taste nothing because I haven’t called the content with HTML files so what I’m trying to do is to try to avoid writing PHP codes inside the HTML files so what I’ll be doing is is that I’m going to read all HTML they’re all HTML content inside the content with HTML and also all the PHP codes inside the template dot PHP ok so now let’s open up our PHP tag and also let’s close it so I’m going to call the content dot HTML file ok so and if you can look here like like the content of HTML is inside the HTML folder and this is our foldaway web template dot PHP so I’m going to declare a variable a and I’ll call it file which is equal to is going to be HTML folder slash content dot HTML right so I’m also going to say file is equal to file get contents so we are going to use file get contents a function to face the content of of of our finally and our file name is going to be file and also close that and we are going to echo echo file right so now if i refresh template dot PHP if i refresh it now get something because we have now called the the content will now face the contents of of our of our HTML right so what if I what if I want to display like different names like and different sign names like my name is and I want to display different names so what I’m going to do is that I’m going to remove this here and I’m going to open up to kill to kill brackets and I can call this one name and also call this one sunny sunny so let’s save that so on my PHP code so I’m going to say fire file okay so I’m going to say file is equal to STR replace so we are going to use the STR please function to to replace what we did here like with two curly brackets who are going to use the STI replace to replace what is written like name with a different name and also signing with the difference on him so I’m going to say STR place and what I’m going to say J I’m going to search for going to search for name Kali so let me also put that inside inverted commas I said comment like that so I’m going to replace it so yeah I can replace with whatever one to replace oh let’s replace this with is going to be my name is you I’m going to replace it with you and the subject that we want to replace is it’s a file and again we also have sunny so let me copy that and paste it below so we’re going to replace sunny sign name so okay so this should be you and then the Sun name I can replace it with me right so now if i refresh the content if I now refresh the page if i refresh the template dot PHP now you see we get my name is you and my name is is me