Lesson #5: PHP Strings

Learn five essential PHP string functions: strlen to measure length, strreplace to swap text, strtolower and strtoupper to change case, and striptags to remove HTML. Each function gets a working code example.
Chapters
Hello and welcome. In this video, we're going to be learning about PHP strings. Now this tutorial is for people who have been through the first few videos on how to set up PHP, how to start with it, and a few basic commands. So first of all, you know a variable starts out with the dollar sign and our variable name. Of course, one of the variable types that you can use are strings. This is a string. Let's look at a few things that we can do. First of all, we can convert numbers to strings, and just like this, just like that. That's basic, but you should have learned that in the Variables video. Let's take a look at what we can do with these strings. We can figure out the string length, strlen. If it's equal or if it's equal to 0, then we know that the string is nothing. However, there is a faster and better method. If isset var one This basically looks for— isset basically checks to see if a variable is set there. But checking to see if var variable isset on the first character, then— or if it's not set, if it doesn't find any characters at the first one, then it will know that there's no character there and there will be no character ahead of that. Which means that it's 0, so it's empty. We can remove from a string very simply like this, str_replace. Now we choose the word that we want to replace. Then we choose the word that we want to replace it with, and then we choose our target, which is the, uh, the variable. Our variable.
Echo new.
Save that and go into here, strings. Here's our first string, this is a string, and then after our replace, it changed string to string only weird. We can also do a few things such as str_to_lower, which turns everything into lowercase, or to_upper, which turns everything into an uppercase. There's also another useful little tool where it stops a hacker from putting in PHP variables or stuff that would ruin or hack your site. Well, it's called Strip Tags. Basically, it removes HTML and PHP tags from the From the input. And we didn't have anything out. So that is basic strings. Very easy. Strings are the most used variable ever. There is a lot more to learn. You can go to PHP's website and Google or look up some strings, and they have a full list of all the PHP strings. Remember, these are just a few of the most common. There are a bunch of other ones that will help you in your future projects. Thanks for watching.
Thanks for watching.










