 Okay, continuing our PHP tutorials. We are going to be taking a string of text today and splitting it with a delimiter. So here we go. I'm going to start by creating a PHP file here. I'll call it split.php. And when I go into it, I'm going to, what I probably should have mentioned in my previous tutorials, I mentioned this in most of my tutorials, is I'm using Vim as my text editor. Feel free to use whatever editor you feel comfortable using. That's kind of a personal choice. Just make sure it's not a word processor. You want to use some sort of text editor or something designed for editing scripts. Anyway, create a file called split.php. Added my PHP tags so that I know everything in between this here and this will be PHP code. And the first thing I'm going to do is I'm going to make a string and I will call it, what should I call it? Well, we've been working with names, so I'll call it names. So I'll say dollar sign names and I'll say equals and each line of code with a semicolon. And I'll just put in a few names here. I'll say luke, I'll say comma richard and I'll say Kirk. Okay, and so I have three names here separated by commas. And on the next line, what I'm going to do is I'm going to do what's called splitting that. So what I'm going to do is I'm going to actually replace the original string here or the original variable. You can create a new one. Actually it might be a good idea to create a new one. So I'll call this one name list and I'll call this one names. I think that'd be good. And then I'm going to issue the split function and pass it first before we pass it our name list variable. I'm going to tell it what I want to split it by. This is a delimiter character that we're going to be splitting by in this case, it is a comma. And so comma and so that's inside quotations and then a comma and now we're going to pass it the variable holding the names, which in this case is name list, sorry. Okay, so what we have so far, we have created a variable that equals this string. Then we said, okay, we're going to basically make an array called names. I'm not 100% sure if it's technically, yeah, it's an array. So names and what we're going to do is instead of telling it this is the first item in an array, this is the second item, this is the third item, we're going to say, okay, here's a function called split. We're passing it the list of names, so this list and each item is separated in this case by a comma. Okay, so we got that. So now I can say echo and I can echo out dollar sign name. Now remember, computers start counting at zero, so we'll say names, zero will be the first name in this case, Luke, and then we'll give it echo names. Names and in this case, I'll say two, which would be Kirk, so we're skipping Richard here. We can also put this like this, since we're working with HTML here, put these in with line breaks here. Okay, so if I was to save this now, come up here, if I have to refresh this, we've got our split PHP. When I click on this, we should have two names, Luke and Kirk. There we go. So let's have a quick look at the HTML. They're printing out on the same line because there is no new line character, we're giving it line breaks. If we wanted to, just to make our code a little bit clearer, we could put the backslash N in here, which is a new line character. So now, if I was to refresh this, things look the same on the webpage, but if I was to work with the code, it's a little bit easier to read because each thing's on a new line. So once again, we'll quickly review on what we've done so far. We've created a variable that has a string in it, which is three names divided by commas. Then we create an array called names. We use the split function past it, our string and what we want to split it by. In this case, a comma. Now, we don't have to use a comma because let's say there's commas in your string already, like you have an address or something in there. You can use other characters in this case, such as a pipe character. So as long as we put here what we want to split it by, and those are within our string here, the output should be the same. Warning. Oh, maybe you can't use a pipe character. Maybe if I empty. Okay, that was a bad example. I'm sure someone will comment on that, but let's try just spaces. We'll split each name up by a space, and I will refresh this and there we go. Now it's split and this is our current HTML output. This is our previous, you can see it's identical. We're just splitting things by different characters here. Now, as you can see, we've created an array here. So we have names zero, names two. We also have Richard, which would be names one. So they're each in their own little space, but we can actually create a list of names and give each of them their own variable name. So let's do that now. We're going to, let's see. We got, we'll use the same, well no, a better example would be something like splitting things up once again by a comma, and here I'll say, I'll give this guy a last name, and we'll give him an occupation of diner owner. Okay, and once again, we will split this with a comma, but instead of just putting it into a regular array like this, what we're gonna do is we're gonna create a list. So I'm gonna say list, and then in parentheses here, I'm going to list what the three separate things, because I know in this case there's three separate things. What I'm gonna do is I'm gonna say dollar sign F name, and then I'll say comma, and I'll say dollar sign L name for last name, and I'll say dollar sign, I'll just say dollar sign OP for occupation. So now what's going to happen is not only are we going to split this string by commas, but what we're going to do is instead of giving them each a number, we're actually putting them into different variables here. So instead of echo name, what I'm gonna do here is I'm gonna say first name, colon, and then I'll say dollar sign F name, whoops. Here I will say last name, and that should be name, not names, colon, and I'll say dollar sign L name, and then I'll do another line, I'll say echo, job title, colon, dollar sign OP, and we'll give that a line break as well, and new line character. Okay, so we should get three lines of output if I've typed everything right here. We'll save that, refresh this, and here we go. We have first name, last name, and job title, and it's a little bit easier this way. You actually have variables that represent each thing rather than an array that you may not know. Hey, what is the first item in the array, the second item in the array? Here we know F name means first name, and of course you can always add in other HTML here. Maybe make it look a little bit nicer. Once again, this is very basic code, but you should probably want that in there. So basically I'm just making, and once again you should definitely know HTML before you start moving on to something like PHP. But I'm just making everything bold here, not everything, but the first portion of each line. We'll save that, we'll refresh it. So it's a little bit clearer to read because this is bold and this is not. So definitely if you're actually making a website you can make it look a lot nicer than that. But you got the basic idea here. Well, quickly, well quickly review. We are creating a variable here that contains a string. This is the string, it's a first name, last name, and job title or occupation divided by commas here, separated by commas. Then we're creating a list, and we're giving each item in the list its own variable name. And I corresponded the variable name with the item that it's equal to. So F name for first name, L name for last name, OP for occupation, and then we're splitting. We're using the split function. We're passing it the variable or the string that we've already created, and then we're also passing it what we want to split it by the delimiter here. Once that's done, each of these variables have a new value, and we're echoing those out on two lines in HTML format. And that is pretty much it for this tutorial. That is the split command. The next tutorial we're gonna go over, we're gonna go over the explode command, which is pretty much identical, but with a few different, a few little differences, but we're definitely gonna go over that in next tutorial. So I hope you enjoyed these PHP tutorials I'm working on. It's a series I'm working on. This is video number six, I believe. Check out, there should be an annotation to the playlist. So click on that, watch the full playlist. If you're enjoying these PHP tutorials, definitely give these videos thumbs up, comment, let me know. That way I know what you guys are interested in. And once again, this is just, you know, working on server side web scripts. PHP is a very common one. And we're gonna definitely be using this in cooperation with client side scripts such as JavaScript or libraries for JavaScript such as jQuery, which I've been doing tutorials on. And we'll be able to make very powerful applications that are easily shared among pretty much any device you have, as long as it has a current operating system on it, regardless of what the operating system is. That's once again, one of the great things about server side scripts is it's running on your server which you're in control of. So you can do pretty much whatever you want on that end and just output the information to a web browser. So I thank you once again for watching. Please visit my website, filmsbychrist.com. Chris with the K should be a link in the description. And I hope that you have a great day.