 Okay. Continuing our PHP tutorials. Right now, I believe we're on tutorial 9 if I haven't lost count. There should be an annotation to the entire playlist. If you haven't watched those, you may want to go back and check those out, the previous tutorials. Also, working with server-side scripts here, you should be familiar already with HTML because I mean pretty much everything you do in here is going to be outputting something in HTML format or something that will be used in HTML. In our last tutorial, we used the Explode function to split a string up and give us some output here, and that was from a string that was within the script. Well, today we are going to do the same thing, but instead of with a string within the script, we're going to read a file, a CSV file, a file with lines that have information on them that are split up by commas, and we're going to basically do an output like this, but for each person within that list. I've already created a list. Let me have a quick look here at names.csv. We have a list of names here, and we have the first column. Each column is split up by a comma in this case. First column is the first name of a person. Second column is their middle name, or sorry, middle name, their last name, and the last column will be their job title or occupation. And then some people have more than one title because they have more than one job, so I've done those split up by, whatchamacallits, pipe symbols. So let's go ahead and start working with this, and I'm going to create something called a file called csvexplode.php. Once again, we're going to start off, we're going to say that we're working with PHP, so we'll give our PHP tags there, open and closing the code, and now we are going to start with a file. So we'll say $file. So this will be an array that contains the contents of a file, and that file, as I just showed you, is called names.csv, and each line, each command with a semicolon. So next, we are going to say for each line, dollar sign line, sorry, file as line, sorry, I'm going to clear my mind because I keep on saying the wrong things here. So real quick, we're going to, we're creating a for loop. So we're creating an array here called file. The file is going to contain the contents of this, each item in that array is going to be a line within this file. Then we're going to say for loop, and we're going to say for each line in this file. So we're creating a variable here, you can call it whatever you want, but we're just calling it line in this case. Within our array of file, we're going to go through and loop. So real quick, we're just going to say echo. And for right now, we'll just say to print out the line with a line break HTML tag. And that's it for right now. Let's save that. Let's go back to our folder here, f5 to refresh this csv explode when I click on that should run our code here. And there we go. Basically, right now, it's just displaying the, the contents of the text document, the csv file. But what we're going to do now is we're going to use what we learned in the previous tutorial to split that line up. So I'm going to just delete that line right now from our code. And what I'm going to say is I'm going to create a list. So we're using a list function here and we're going to say dollar sign F name comma dollar sign L name comma dollar sign. We'll say I was using the last tutorial OP for occupation kind of OP is kind of a weird abbreviation for occupation. But that's what I'm going with. And we're going to say that equals and we're going to pass the we're going to use the function explode. And we're going to say we're going to split the lineup by a comma. So dollar sign line. And don't forget your semicolon. So so far what we've got, we've got nothing outputting. If we run this script, let me save real quick here and show you if we were to refresh this, we get nothing on the screen because nothing's being printed. It's running this, but we're having any output. So here we're saying for each line within this file, we're creating a variable called line that we're taking that variable line, which is the line from the file. And we're saying look at that line and split it by a comma and each column which is divided by a comma, the first column is the first name, second columns last name, last column is the occupation. So now I can do something like this echo H one and I can say dollar sign F name. Or actually I can go do last name first L name comma dollar sign F name H one and semicolon there. And then I'm going to say echo. And once again, there's some HTML here to make it look a little bit nicer. We'll say job title, dollar sign OP, close our quotations, semicolon to end the command. So now when I run this, it should go through each user within that file and basically format their information accordingly. So I'll come up here, I'll refresh and we've got the first person and their job title. And we're going by last name then first name. And we can also come in here and we're going to I think it look a bit nice if we say, well, we can put this up in the same line here rather than a new line. Let's do a horizontal line break. There we go. So now everyone's divided up nicely. And at this point, let's let's do something from a previous tutorial and sort that information out alphabetically. So I'm going to do is before we even run our for loop, I'm going to say sort. And we're going to pass the sort function, our file variable, which contains all the information from our file. So if I was to refresh this, now they are in alphabetical order, but they're alphabetical order in this case by the first name. And I didn't think about that when I started this tutorial. So even though we're displaying the last name first, they're going alphabetical order by first name because we're going by the name there. And that's a whole another tutorial. So actually, let's not do that. But something that we may want to do here. And we could actually, maybe I'll plan that for the next tutorial. I'll go over that. But I won't get too off course here. We'll see some people we said had multiple occupations. Like Rory here has a she's a student and she's a journalist up here. Kirk, he's a real estate agent. He's a cable installer. He's a movie usher. We can actually use the explode command again, or at least we should be able to. I haven't tried this yet. I mean, I know you can. But I haven't actually done this to make sure I type everything right. But what we're going to do here is we are going to take that last variable, the OP, and we're going to split that up. And then we can display things, maybe in a list. So what I'm going to do here is I'm going to say dollar sign job equals explode. And we're going to say here pipe symbol. And then I'm going to pass it dollar sign OP. And next, don't forget to finish that line with a semi colon. What I'm going to do is I'm going to say for each. And we're going to do our for loop here. And instead of just putting things like this, let's actually put them in a list format. So what we're going to do is actually, let me cut this line and paste it up here. And now we'll say job title. And then we'll also put in here. Instead of the horizontal line break here, I'm going to say UL because I'm going to start an HTML list. So UL. And then I'm going to say echo li for list. Close that tag as well. So we don't forget later on. And I am going to say our for loop. We're going to say for dollar sign OP. I'm sorry. Job. And I'll explain all this again in a minute. As dollar sign, I don't think it'd be a good idea to use job again. So we'll say title. I'm going to say dollar sign title here. And then after the for loop I'm going to do another echo. And I'm going to echo to close our UL tag and also put in our horizontal line. Okay, let's split some of this up, make it a little bit easier read, put some spacing in there. That goes together. Okay. So let's look over our code from beginning to well, let's actually save it and make sure it runs before I try to explain it. There we go. Yep, it worked. Now there's a blank spot here. And that's just because how I created the text file. I put one too many pipes in there. But besides that, my code is all right is my text file. It's a little messed up. So what we're doing once again, we're creating an array that looks at this file. And each item in the array is a line in the array. So we're going to say a for loop. Look at this file and each item is a line, we're creating a variable called line. Then we're going to take create the list using the list function here. And we're going to explode or split the line. So each line by a comma. So right now, each time we go through this loop, it's a new person in the list. Then we're going to echo their name, both last and first. But instead of just displaying their occupation, since some people may have more than one, we're creating a new array called job. We're using explode to split the occupation by the pipe symbol, just because that's how the text file is set up. Maybe split some other way. Then what we're going to do is we're going to echo job title and start creating an HTML list. Then we're going to say for each item in job. So the new array we created up here, which has each job for each person, we're going to create a new variable called title. Still with me? I hope so. If you've done programming in the past, this should make sense to you. If you're new to programming, hopefully I haven't lost you. And then we're just going to echo a new item in the list for each job title they have. And lo and behold, that's how we get this up here. So we got a person last named Danes, first named Luke, guy's job title, diner owner. Emily is unemployed. We got Richard, he's insurance salesman. But we come down to someone like Rory. She's a student and a journalist. Then here we got Kirk. Kirk has a few different jobs. Real estate agent, cable installer, movie usher. And once again, we have this empty line and I'll show you why. If I save that and go back into our text file, you can see that I have an extra little tailing pipe symbol right here. And so it's splitting it and looking what's over here and there's nothing over there and that's why this is blank. So really, I should delete that out. We'll save it. And if I was to refresh the page up here, you can see it quickly fixed. So I think this story is running a little long. I hope you enjoyed it. Once again, if you're familiar with programming in other languages, you've done stuff like this before. So hopefully it made sense. If you're new to programming, hopefully I explain everything well. Of course, you can always come to my website, filmsbychris.com. That's Chris with the K. Click on the help link. We'll bring you to the IRC channel. And in the IRC channel, I'll be able to answer your questions hopefully. And if I'm not there, don't come in there just looking for me. Other people there, you can try to ask them for help as well. It's not all about me. It's about us. Also, you can ask a question in the comments below, but you may not get an answer because one of the worst places to ask questions and get answers is YouTube comments because they're so messy. So most likely if you ask a question below, the technical question, unless I can answer it in one sentence, you're probably not going to get an answer other than meet me in the IRC channel. So once again, if you're enjoying these PHP tutorials, please give this video a thumbs up, comment below, let me know if you like it. Comments are great in the comments section because that's what they are for. It's just not the best for asking questions. Once again, I thank you for watching. Hope you visit my website and I hope that you have a great day.