Bill Rosener: Hello! This is Dr. Bill Rosner. Welcome back in this video. You're going to learn how to include files using Php, and this is a very, very, very common operation used when you maintain a website. Maybe you've got in this case a header, or you've got a footer, and you want to include that. Because let's assume you've got a hundred documents or a thousand documents on your website. And if you want to change
Bill Rosener: the footer or you want to change the header. You don't want to have to modify a thousand documents in this case. We're going to simply create one header, one footer, and then we'll include that file. So if we ever want to make changes, we make one change, then that automatically gets included. We're also in this one. We've taken one more level. Further, we'll be including this image and this here text.
Bill Rosener: So let's go ahead, and we'll tell you while I'm right here. Let me run through this. So if I take a look, here is the assignment, 6 folder, and we're going to see some information here. So you're going to want to create a folder called State information and then download all this information. So we've got Alabama data dot txt, and I've got a picture of Alabama.
Bill Rosener: Then I'm going to have Alaska data.
Bill Rosener: Then I'm gonna have Alaska image, and then also with Arizona, I'll go ahead and do the 1st 2. I'll let you run through Arizona
Bill Rosener: or some other state if you want.
Bill Rosener: Okay. And now, taking a look, here is the final product. Well, if I press on Alabama.
Bill Rosener: it's going to include the header. It's going to be including this image and some text. Then it's going to be including the footer.
Bill Rosener: And if I was to press on. Here was the header.
Bill Rosener: Here is the footer that includes that information, and then here would also be Alaska
Bill Rosener: includes that includes this and this information. And again, when I'm finished here, I'm going to go ahead and maybe modify the header or the footer, maybe even both, and then we'll see. Wow! I've only got to make one change. So if I've got all 50, if I've got 50 documents here for every State, I make one change, and then automatically all the headers and the footers would be modified accordingly. There.
Bill Rosener: okay.
Bill Rosener: now that we know what we're gonna do, let's go ahead and get started. So the very 1st step you want to do is open up an editor I'm gonna use visual studio code.
Bill Rosener: and, as I probably should have mentioned, here is I've given you the source code for the footer, and an image
Bill Rosener: also for the header, and then even the code for Alabama.
Bill Rosener: And well, I'll kind of walk through that here in a second.
Bill Rosener: So anyway, here's I'm open up the visual studio, and I'm going to start off with the header.
Bill Rosener: I'm just gonna come right up here to file new text file paste that.
Bill Rosener: And we just got some information header to your company name. Okay.
Bill Rosener: these links wouldn't even work. They just go to home, dot HTML news products, and they're not even a valid Urls. But you could easily modify that if you wanted to home news, and I've got some non-breaking spaces at the end. But we'll go ahead and save this. I'm gonna come right up here to file.
Bill Rosener: save as this is going to be header got HTML?
Bill Rosener: And right up here is Header Dot. HTML.
Bill Rosener: Now, what I'm gonna do is come right up here and create another text file for the photo, new text file.
Bill Rosener: go ahead and get my phone
Bill Rosener: and paste that. So here in the footer I've got a couple of line breaks. Have the company name and email address and a phone number.
Bill Rosener: I'll go ahead and save this, save as.
Bill Rosener: and that will be my footer, dot. HTML,
Bill Rosener: okay. And if I was just to kind of log, here's some. Here's the footer. Here is the header, and that
Bill Rosener: soon as I hit refresh I could see the footer and the header, and here in a moment I'll be uploading those coming back here to visual studio code. I'm going to come up here to file new text file. And now we'll start actually working on
Bill Rosener: Alabama.
Bill Rosener: Okay.
Bill Rosener: you know, delete that top one. We're gonna start our HTML, we're going to have a head tag. Start the body. Notice right away. We're going to go ahead and include that header which we just got done working on. Then down at the bottom. We're going to include the footer that we worked on.
Bill Rosener: Then we're gonna have a header to tag that, says Alabama. And here comes some little magic, I tell you. Let me 1st save this, and I need to make sure that I save this as Alabama lowercase, dot, Php, file, save as
Bill Rosener: Alabama dot Php and save.
Bill Rosener: Okay, so what's gonna happen here? I'll tell you what, maybe even I need to. Why does Alabama need to be lowercase? And that is because it needs to match.
Bill Rosener: I want it to match here. So I'm gonna be looking for Alabama data dot txt. And then Alabama dot jpeg. Here's the image there. So everything here is lowercase. So what is going to happen?
Bill Rosener: This is going to grab the current file name, which is Alabamaph, all lowercase, and I could have actually used some Php code to convert it to lowercase. And so then I could have given this a capital letter. But I think it makes a little bit easier. I'm now going to find the location of the period and use the substring and grab everything to the left of the period which is Alabama, all lowercase. The image name is then going to be
Bill Rosener: Alabama dot Jpeg, and notice it's looking in state information. So one of the 1st things you're going to do is create a folder
Bill Rosener: called state dash information.
Bill Rosener: and you may even want to create a folder. 1st of all, just called assignment 6 to place all this information in.
Bill Rosener: Okay?
Bill Rosener: And then so anyway, we're creating a folder called, you're going to create a folder called state information. And you're going to download that stuff. So it's going to be looking in state information for a file called Alabama Jpeg, and then all of Alabamadata dot txt.
Bill Rosener: Okay, well, let me go ahead and save that.
Bill Rosener: It looks like it already is. And now let me do one more. I'm gonna let you guys do 3. I'm gonna do 2 of them. Here. I'm gonna come up here to file new text file.
Bill Rosener: I'm just gonna grab this code, here, copy it, paste it.
Bill Rosener: And this one I'm going to call Alaska. So I'm gonna come right up here and go to file, save as
Bill Rosener: I'm gonna call this one Alaska dot. Php.
Bill Rosener: okay, now, I need to actually make some changes here, Alaska and
Bill Rosener: Alaska. But you can see how few changes I had to make here. So the title is, Alaska got the Heritage tag.
Bill Rosener: taking a look at the file name.
Bill Rosener: extracting everything to the left of the period, which is Alaska, and it's going to use that to fill in the information.
Bill Rosener: Okay, we're ready. I need to say this one.
Bill Rosener: Okay.
Bill Rosener: Now I can go ahead and come over here I can hit a view I can hit refresh.
Bill Rosener: So now I've got all this information, and I'll need to upload that.
Bill Rosener: Okay. So make sure again. You might even want to go one level deeper. 1st of all create a folder called assignment 6. Then within there you're going to create a folder called state information and feel free just to grab the information right here save all that within there.
Bill Rosener: Okay, well, let me come back here and
Bill Rosener: So anyway, let me go ahead and check it out. So we've got well, here. It was right here, so we've got state information. I've got my 2 files, Alabama and Alaska. I've got the header and the footer and let me go ahead and check those out. I'm gonna come right up here. I'm going to hit refresh.
Bill Rosener: So I'll start with Alabama.
Bill Rosener: And sure enough, it is, grabbed the header. It's grabbed the footer, and it's grabbed that image. And this text.
Bill Rosener: and I'm going to choose Alaska. Same thing.
Bill Rosener: Okay. Now to see the the beauty of why, including files. And let's come over here to let's go ahead. And 1st of all, I'm gonna choose the header, and maybe I'm just going to choose rather than news. And I'll change this to a directory.
Bill Rosener: Okay? And then we'll go ahead. I need. If I can see that I need to save it. File, save.
Bill Rosener: And then over here on the footer, let me just change the phone number
Bill Rosener: to 4, 3, 2, 1. Just change the order of that, and I'll go ahead and save that.
Bill Rosener: Okay. Now I'm gonna go ahead and upload, and all I need to do is upload these 2 files, those only 2 files that have changed upload those.
Bill Rosener: And I'm gonna go ahead and override. I'm just gonna always use this action.
Bill Rosener: Okay, now I'm gonna come back.
Bill Rosener: Take a look.
Bill Rosener: We'll start with Alabama.
Bill Rosener: And sure enough, now it says, Directory 4, 3, 2, 1
Bill Rosener: and same thing with Alaska Directory and the new phone number. So if I had 100 documents and I've included this file, I just need to make one change. I don't have to go through each single file making or document on the website making that change. Well, hopefully, in this video, you learned about the power of includes and how simple it is. And I'll catch you next. Video. Thanks a lot. Bye.