William Rosener: Hello. Welcome back. And this assignment will continue with the previous video on string manipulation, this time using PHP.
William Rosener: So let's start by taking a look at once you learn how to create so will allow the user to enter a name, and I'll put my name here.
William Rosener: And when I hit extract name I'm gonna take a look up here. We're going to see that it goes really quick, probably, it goes to the server.
William Rosener: Comes back with the data there. And this game is the case, it's going to display the first name and last name is just like a JavaScript will make sure that we can that this will work with any name.
William Rosener: Not just names with four characters but names with shorter or more characters and which is also working there and then to challenge you.
William Rosener: I'll probably also go ahead and see if you guys can do this and that is will have three names. So I'll just go ahead and type in
William Rosener: Amy Elizabeth roesner and I'll hit extract name. And sure enough, it's going to extract the first name three characters Elizabeth middle name and last name there. Okay. Well, now that we know what we want to do, I'll let's get started here.
William Rosener: So the first step would be to open up some basic editor. I've just got notepad here, I'm going to go ahead and and maybe save a little time here probably save more time if I simply started with the previous assignment there on JavaScript. But what to start from scratch here.
William Rosener: Okay, we've got a basic HTML restart the smell closes. We've got a head. Maybe I'll come right up here. And the title.
William Rosener: And I'm going to go ahead and type in string manipulation.
William Rosener: And I'm going to type PHP and then maybe I'll just simply come along and grab that
William Rosener: And come down here to the body.
William Rosener: Place that header to tag type of clothes, my header to tag.
William Rosener: And it'd be good and put your name.
William Rosener: And we'll go ahead and put a paragraph break here.
William Rosener: Okay, so nothing too exciting there so far. Maybe we'll even just before even saving it and checking this out a little bit more code here. Let's just go ahead and we'll start our form.
William Rosener: And we'll go ahead and close the form
William Rosener: Okay, so what's going to happen is we're going to put a command button in here. And when I press on it. What is it's going to do. It's going to keep calling itself over and over every time I press the command button effect column PHP self them.
William Rosener: Okay, and maybe at this point we can go ahead and also go ahead and type some information here.
William Rosener: Start the forum. If you want to
William Rosener: You could start off with a default value. And then when you're finished here. I think I forgot the JavaScript. But go ahead and delete that this way when you're checking it out. So you have to keep typing and and arm.
William Rosener: And let me put a little paragraph at the end of that and I've got a command button and then I'm going to go ahead and put a text area tag.
William Rosener: I'm just going to type in test right here.
William Rosener: And a close on the text area.
William Rosener: Okay, so we're gonna start our form close it. We're going to have a place where the user can enter in the complete name of a command button and then a text area or display the results. Let's go ahead and save that somebody come up to file. I'm going to go to save as
William Rosener: I'm just going to say this on a tab. I'm going to go ahead and call this one assignment 11 PHP dot PHP. So make sure you know where you're saving it. Make sure it ends with extension PHP. In this case, I've called assignment 11 dash PHP and let's go ahead and save that.
William Rosener: Okay, just check this one. We've got uploaded to a server someone to come along and hit refresh here.
William Rosener: And now I can see it's being displayed here and I'm just going to upload it to my temp folder so simply right click and upload
William Rosener: OK, now I'm going to come back here on this upload it right here. So I'm gonna simply hit
William Rosener: The refresh button. And sure enough, here it is. So let's go ahead and press on the sun loving and there we go. Nothing's working yet, but it's coming along here.
William Rosener: Okay, let's start working making this code work here. So I'm gonna come up here. Probably the very first thing I'm gonna do is I'm going to go ahead and create a few variables.
William Rosener: So I'm gonna start way up here at the top.
William Rosener: And I'll tell you what I maybe I'll go ahead and close my PHP.
William Rosener: And I'm going to create two variables. I'm going to
William Rosener: Affect assign them the knowledge strength to double quotes side by side and then we'll go ahead and get our little error checking in.
William Rosener: So you can take a look here.
William Rosener: Now what's going to happen is when we call this we're going to actually be looking at the information that has been posted and it will make sure that there's a effect. No malicious data there. Let's go ahead and grab a little bit more code here. I'm gonna simply copy this and paste it.
William Rosener: And maybe all I could even make sure I get this close in one. So this here bracket here is going to close this one and then this one here is going to close up here.
William Rosener: So what's going to happen is when I'm going to come down here. And the first time I press the command button, it's going to call itself.
William Rosener: And we're going to take this information and complete name, and it's going to call itself, it's going to go. Okay. Is it not empty, and in this case here.
William Rosener: I've got some information. So it would not be empty. So it's going to go ahead and take this information that has been posted and I'm going to call test input on it.
William Rosener: Just to make sure. If we're going to trim and these spaces at the beginning. In the end, and then we're going to kind of remove any data that could pause by a strip by this strip slashes and making sure we've got removing special characters there.
William Rosener: Okay, at this point, we've now got a couple of variables declared we're passing our data there. But we're not really doing anything. So I'll tell you about what we could do, if nothing else is let's just go ahead and say, Tim string right here.
William Rosener: And let's just put in test.
William Rosener: Okay, so here at the top. I've declared. It's not the very first time when you call it just so
William Rosener: Something appears and actually it was just so we don't get an error message so that we got a variable that's undefined. So we've got a variable and it's got a default value of nothing.
William Rosener: Okay, now what we're wanting to do is we want to come down here to the bottom. And we actually want to display the hat. So rather than display and
William Rosener: Test this way. I'm going to go ahead and paste
William Rosener: And now what's going to happen is it's going to display what's ever in temp string. And just to maybe change this, just so you can actually see something change here. I want to put test 123
William Rosener: So again, what's going to happen is when I call it this. You know, the first time I press on the command button, it's going to call itself. It's going to come up here.
William Rosener: And it's going to affect depending on again, I've got a some information here and complete name, so it's going to say, hey, K. It is not empty. So I'm going to take that information and displayed in complete name,
William Rosener: Then I'm gonna say attempt string is equal to test 123 and we'll be working more on this and then it's going to come on down here and display that
William Rosener: And I'll tell you what, let me go ahead and make one more change here. I want to make sure that I tell you what, I'll leave it alone, then I'll come back and change it. The next time someone to come to File, Save.
William Rosener: Again to view the latest changes. I need to upload this to the server. Someone upload
William Rosener: I'm now going to I'll even back up a step.
William Rosener: Hit assignment 11 I'm gonna hit extract name.
William Rosener: And sure enough, it is now displaying test 123 okay but I don't want it to always say my name here. I want to make sure it's works for any name here. So now, at this point, I'm actually rather than
William Rosener: Just deleting that value. I want to make sure that it keeps passing that st whatever information is in there, it passes it back the second time.
William Rosener: Okay, so what is going to happen is when I call it again. It's going to simply echo what was already incomplete name so just an effect keeps populating this input field with them, what was already there. Okay, let's go ahead and I'll say that.
William Rosener: I'll tell you wouldn't really make too many changes it, but we could say that. Anyway, and upload that
William Rosener: And hits stream manipulation here reload.
William Rosener: Reload refresh. But, or you can simply come back and click on it fresh and now we can go ahead and type in a name.
William Rosener: It's still not working now. But when I hit extract name, it's going to display test 123
William Rosener: Okay, so here's where we're now really need to spend some time working. And to do that, I'm going to first of all
William Rosener: Well, I'll just kind of break this up line by line.
William Rosener: I'm gonna say space position. And in this case, I'm going to use. It's called the functions called string position.
William Rosener: I'm gonna take a look at the string position. I'm gonna take a look at the variable complete name, and I've got a single space within these double quotes here. So what's going to happen is I'm going to find out where
William Rosener: In I could do what I did earlier.
William Rosener: Okay, so what is going to happen is haven't executed this code here space position is now going to have a value of four. And if you wanted to. Let's go ahead and just to check them will go ahead and put space position here.
William Rosener: Okay, so we're going to find the space position and then we're actually going to place it in Tim string, which then gets effect echoed or displayed in our text area tag. So let's go ahead and save that.
William Rosener: We'll go ahead and upload this
William Rosener: And reload or refresh.
William Rosener: And sure enough, I'm finding the seven here. So if I put in Bill extract name. Sure enough, I'm getting the for them.
William Rosener: Okay, we don't really need to
William Rosener: Display that position, the space. So now we go ahead and actually
William Rosener: On the first name.
William Rosener: And then we'll find the last name. Okay, so we found the space. It was in position for. So now what I can do is I want to extract
William Rosener: The left for characters. Some say the sub string on the specify the stream extracted from on the specified my starting position.
William Rosener: And then how many characters to extract and I went to extract for so I found the space and position for
William Rosener: And I'm an extract for that's typically why a lot of languages. Start strengths and arrays at zero. So, notice I didn't have to do any mindless in here. I didn't have to go. Okay, I found the space that
William Rosener: Position, for I don't have to go for minus one. So, I found it helpful. That makes sense. Here I found it at position for the space. So I can now extract four characters them. So I'm starting position zero and extract for positions are for the four characters there.
William Rosener: Let's just go ahead and I get last name as well.
William Rosener: Yeah, Tim. I've been through a little trim on that one.
William Rosener: Okay, so here's a last name. I'm going to take the sub string and all, am I going to do is, again, I found the space. If I had bill, it's going to find it in for
William Rosener: I'm not going to go four plus one is five, and I'm going to extract here to the end and place that in last name. This is simply going to remove if there were extra spaces around last name. I'm gonna go ahead and remove those.
William Rosener: OK, now let's go ahead and start building up attempt strain.
William Rosener: Okay.
William Rosener: And in this case here on the set. First of all, Miss attempt string able to the know strength and I'm going to set a couple ways of doing it. This are typically have done it. I'm gonna say attempts trying is equal dog. What's interesting concatenate it with
William Rosener: This is going to be a static string here along with the variable and then a new line. So it's going to say first name, maybe bill done a new line. Then I'm going to take this right here. So I've got two choices on this. I can either put
William Rosener: Equals
William Rosener: $1 sign temps string.
William Rosener: Period, which is a string concatenation. The rest of that or what I can do is, I'm not sure if you saw that there. I'll put it back the way it was.
William Rosener: So what this is going to do is it's going to say concatenate to itself. So I can either say Tim string is equal to Tim strain what's already in there, plus this new information or I can say Tim string is equal to period equals
William Rosener: Which is going to simply concatenate this new information towards already there.
William Rosener: And I tell you what, let me just go ahead and finish this all off. Then we'll check it.
William Rosener: And I think we're about finished to
William Rosener: OK, so now what's going to happen is I'm going to take what's in temp string again concatenate didn't last name.
William Rosener: The static string last name long with what's in the verbal last name and then a new line. And then finally, I'm gonna use the string length to determine the length of that. And then finally, rather than display in a space position down here.
William Rosener: We're going to just simply leave temp string alone here.
William Rosener: So I've been all along. I've been building temp string concatenation more and more. This what this little period does it concatenate
William Rosener: Or ads, actually this one does not. That one is period after characters there, but these are string concatenation, which are going to
William Rosener: Concatenate more information to tempt string. And then finally, down here. I'm going to echo or display it within this text area tag. So hopefully we've got everything working right something come up here to file. I'm gonna hit Save.
William Rosener: And I'm going to right click and hit upload
William Rosener: I'm gonna take a look at my browser.
William Rosener: Backup
William Rosener: Assignment 11 PHP. I'll put it a name.
William Rosener: And hit extract name.
William Rosener: first name and last name there. So everything looks like it's working good here.
William Rosener: I was just going to look there look like I had an extra space.
William Rosener: Up again where that's going to be right here. So I'm not sure if you notice that I've got a little space right here.
William Rosener: Let me come right down here and delete that. And I'll tell you what, let me delete this one at the end. So hopefully that removes that leading space. I'm gonna come to File, Save. I'm going to go ahead and upload
William Rosener: That I'm going to press on the reload refresh button.
William Rosener: And sure enough, that so that over and again, a lot of times I'll come back and check out start off with fresh, I'll go ahead and put in, let me type in a different name here.
William Rosener: And extract name. And sure enough, it's extracted the first and last name. So again, that's working with just two names. The first name and last name and then to maybe challenge you just a little bit here.
William Rosener: I'll may have you guys see if you can do this where you can enter in three names.
William Rosener: And this is a PHP. And so again, I kind of looked up here really quickly just to make sure I'm calling the server or, as well as in JavaScript is just executed on the client machine.
William Rosener: Make sure it's called the server. And sure enough, is working correctly there. So hopefully this video you learned how to do a little basic stream manipulation using PHP. So I'll catch the next video. Thanks. Bye.