WEBVTT

00:00.620 --> 00:01.040
Okay.

00:01.040 --> 00:04.940
So next up let's do some more advanced things with the strings.

00:04.940 --> 00:09.650
So in this example here we've got a Unicode text.

00:09.860 --> 00:13.130
So to be honest I just copied this over the internet.

00:13.130 --> 00:16.010
I just don't even know what language that is.

00:16.040 --> 00:20.060
That's not the characters the Latin characters I know.

00:20.060 --> 00:28.400
And for such cases you can't just use strlen because this would completely break it down.

00:29.960 --> 00:36.620
So if I try something like that, this file is called String Advanced.

00:36.650 --> 00:37.910
Let me run that.

00:40.490 --> 00:43.040
Don't even get a result, to be honest.

00:43.250 --> 00:44.210
Maybe.

00:45.440 --> 00:46.940
Okay, so let's run that.

00:46.940 --> 00:50.810
And this says that the length is 15.

00:50.810 --> 00:58.610
Well I'm no expert in this alphabet, but it doesn't really look like 15 characters.

00:58.610 --> 01:09.660
So for such cases we need to use the multibyte versions of string functions and they have this M prefix.

01:09.690 --> 01:17.880
Now watch out when you are working with Unicode, because if you would use any other function that modifies

01:17.880 --> 01:23.160
or does anything to such a string once, it really might corrupt such string.

01:23.160 --> 01:33.210
So if you are dealing with the UTF text multi-byte strings, you need to use those M functions.

01:33.240 --> 01:35.220
Now let's see if this is any better.

01:35.250 --> 01:38.010
Well it looks like five characters.

01:38.010 --> 01:40.980
So now we've got the correct value.

01:41.430 --> 01:49.500
Now another example and something you actually might be often doing is the Urlencode function.

01:50.580 --> 01:54.150
Now let's have an example with URL encoding.

01:54.870 --> 02:02.280
So URL encoding is essentially making sure that you can pass a string safely in a URL.

02:02.370 --> 02:09.030
Now in this example here well URLs contain some special characters that have special meaning like the

02:09.060 --> 02:15.960
question mark, to pass the parameters and the end sign to separate different parameters.

02:15.960 --> 02:24.060
So to be able to pass strings that contains those special characters in a URL, you need to encode them.

02:24.510 --> 02:33.270
So you will run the URL encode function which opposite of its URL decode, which basically lets you

02:33.270 --> 02:35.670
get back the original string.

02:38.100 --> 02:41.040
So let's see how this would look like.

02:42.930 --> 02:43.830
Let me run that.

02:43.830 --> 02:47.580
And this is how this URL would look like.

02:47.580 --> 02:49.770
Now why this is useful.

02:49.860 --> 02:56.280
Well I can pass this text as a parameter to some other URL.

02:56.280 --> 03:02.760
And it would be at this URL encoded can be safely passed.

03:02.760 --> 03:05.610
And then I can decode that.

03:05.610 --> 03:15.520
So when I receive such string and I know it is a URL that I need to use for anything, Then I do urldecode

03:15.520 --> 03:16.960
on the other side.

03:19.420 --> 03:25.840
So let me just copy the encoded version and decode it back.

03:27.970 --> 03:34.750
So if I run that, then I get this original URL which I can do whatever I need to with.

03:34.780 --> 03:40.420
Now this is not only for encoding the whole URLs like you see here.

03:40.450 --> 03:47.920
You might just encode a string that you suspect of having some special characters.

03:48.610 --> 03:51.610
For example, a company name.

03:51.610 --> 03:58.210
If this is Johnson and Johnson.

04:00.610 --> 04:04.990
You can't pass safely such a string as a URL parameter.

04:04.990 --> 04:11.710
It needs to be encoded to cover the spaces and the end sign, etc..

04:13.180 --> 04:17.750
Okay, next up, let's imagine that we have user input like this.

04:17.750 --> 04:21.680
So we might want to present code on the screen.

04:22.040 --> 04:24.260
For example I'm doing this on my website.

04:24.260 --> 04:26.060
So this is useful for me.

04:26.060 --> 04:29.060
But also you need to be wary of user input.

04:29.060 --> 04:37.520
So someone might want to use HTML tags or add some code to input, even if maybe you are asking for

04:37.520 --> 04:38.330
something else.

04:38.330 --> 04:47.120
Maybe you want a blog post title and malicious actors, let's call them this way, might try to, you

04:47.120 --> 04:50.000
know, enter what should not be entered.

04:50.000 --> 04:57.560
And in this case, we would like to basically escape some special characters and escape the HTML tags

04:57.560 --> 05:01.310
so they are not interpreted by the browser as tags.

05:01.340 --> 05:06.560
Instead, they are converted to the so-called HTML entities.

05:07.070 --> 05:14.570
Now with this text, what we would like to do is to use the HTML entities function.

05:14.570 --> 05:16.550
So I know those functions.

05:16.550 --> 05:20.390
Really those functions naming doesn't really make sense.

05:20.390 --> 05:21.450
There are.

05:21.480 --> 05:23.850
Those names are all over the place.

05:23.880 --> 05:27.210
Anyway, let's see how this would look like.

05:27.210 --> 05:33.840
So this is string advanced and this is it.

05:33.840 --> 05:37.170
So as you see it's HTML entities everywhere.

05:37.170 --> 05:45.330
And this is what can be then safely stored and displayed and won't be interpreted as HTML.

05:46.800 --> 05:55.200
Finally let's cover the base64 encode and basically this base64 algorithm.

05:55.200 --> 06:03.570
So this encoding can represent binary data using just a set of 64 characters that are letters numbers.

06:03.600 --> 06:09.900
And it's very useful if you'd like to include some data in your URL parameters.

06:09.900 --> 06:12.030
And this data might be anything.

06:12.030 --> 06:13.950
It can be an image even.

06:14.190 --> 06:19.140
And it's also useful to store some kind of binary data.

06:19.170 --> 06:27.540
So maybe some images or other types of files in databases that don't support binary storage.

06:27.570 --> 06:28.470
Also.

06:28.500 --> 06:32.070
Encoding is used for email attachments.

06:32.070 --> 06:37.230
So let's do something easy with this.

06:37.230 --> 06:42.780
A simple example with just some text looks like this.

06:42.780 --> 06:48.840
And maybe I can just var dump this right away like this.

06:49.650 --> 06:52.800
And let's see how this would look like.

06:54.150 --> 06:57.390
So this is our encoded text.

06:59.490 --> 07:06.030
Now if I instead assign that to a variable I should be able to decode that back.

07:07.080 --> 07:08.370
So now let me.

07:08.400 --> 07:13.080
VAR dump base 64

07:14.820 --> 07:18.720
decode with the encoded text to confirm.

07:21.240 --> 07:22.260
And there it is.

07:22.260 --> 07:28.770
So this is our decoded text that we previously encoded with this base64 encoding.
