Okay.
So next up let's do some more advanced things with the strings.
So in this example here we've got a Unicode text.
So to be honest I just copied this over the internet.
I just don't even know what language that is.
That's not the characters the Latin characters I know.
And for such cases you can't just use strlen because this would completely break it down.
So if I try something like that, this file is called String Advanced.
Let me run that.
Don't even get a result, to be honest.
Maybe.
Okay, so let's run that.
And this says that the length is 15.
Well I'm no expert in this alphabet, but it doesn't really look like 15 characters.
So for such cases we need to use the multibyte versions of string functions and they have this M prefix.
Now watch out when you are working with Unicode, because if you would use any other function that modifies
or does anything to such a string once, it really might corrupt such string.
So if you are dealing with the UTF text multi-byte strings, you need to use those M functions.
Now let's see if this is any better.
Well it looks like five characters.
So now we've got the correct value.
Now another example and something you actually might be often doing is the Urlencode function.
Now let's have an example with URL encoding.
So URL encoding is essentially making sure that you can pass a string safely in a URL.
Now in this example here well URLs contain some special characters that have special meaning like the
question mark, to pass the parameters and the end sign to separate different parameters.
So to be able to pass strings that contains those special characters in a URL, you need to encode them.
So you will run the URL encode function which opposite of its URL decode, which basically lets you
get back the original string.
So let's see how this would look like.
Let me run that.
And this is how this URL would look like.
Now why this is useful.
Well I can pass this text as a parameter to some other URL.
And it would be at this URL encoded can be safely passed.
And then I can decode that.
So when I receive such string and I know it is a URL that I need to use for anything, Then I do urldecode
on the other side.
So let me just copy the encoded version and decode it back.
So if I run that, then I get this original URL which I can do whatever I need to with.
Now this is not only for encoding the whole URLs like you see here.
You might just encode a string that you suspect of having some special characters.
For example, a company name.
If this is Johnson and Johnson.
You can't pass safely such a string as a URL parameter.
It needs to be encoded to cover the spaces and the end sign, etc..
Okay, next up, let's imagine that we have user input like this.
So we might want to present code on the screen.
For example I'm doing this on my website.
So this is useful for me.
But also you need to be wary of user input.
So someone might want to use HTML tags or add some code to input, even if maybe you are asking for
something else.
Maybe you want a blog post title and malicious actors, let's call them this way, might try to, you
know, enter what should not be entered.
And in this case, we would like to basically escape some special characters and escape the HTML tags
so they are not interpreted by the browser as tags.
Instead, they are converted to the so-called HTML entities.
Now with this text, what we would like to do is to use the HTML entities function.
So I know those functions.
Really those functions naming doesn't really make sense.
There are.
Those names are all over the place.
Anyway, let's see how this would look like.
So this is string advanced and this is it.
So as you see it's HTML entities everywhere.
And this is what can be then safely stored and displayed and won't be interpreted as HTML.
Finally let's cover the base64 encode and basically this base64 algorithm.
So this encoding can represent binary data using just a set of 64 characters that are letters numbers.
And it's very useful if you'd like to include some data in your URL parameters.
And this data might be anything.
It can be an image even.
And it's also useful to store some kind of binary data.
So maybe some images or other types of files in databases that don't support binary storage.
Also.
Encoding is used for email attachments.
So let's do something easy with this.
A simple example with just some text looks like this.
And maybe I can just var dump this right away like this.
And let's see how this would look like.
So this is our encoded text.
Now if I instead assign that to a variable I should be able to decode that back.
So now let me.
VAR dump base 64
decode with the encoded text to confirm.
And there it is.
So this is our decoded text that we previously encoded with this base64 encoding.