WEBVTT

00:00.320 --> 00:01.130
Okay, now let's see.

00:01.130 --> 00:03.050
How can we manipulate the strings?

00:03.080 --> 00:09.350
Let me define a variable and just type hello comma world.

00:09.680 --> 00:10.970
Something like this.

00:10.970 --> 00:15.050
And now how can we access individual characters from the string?

00:15.050 --> 00:16.910
Well, same as with the array.

00:16.910 --> 00:19.370
We just use the square bracket syntax.

00:19.370 --> 00:21.980
So let's see what this would give us.

00:22.070 --> 00:24.020
This zero.

00:24.050 --> 00:26.000
This should give us the first character.

00:26.240 --> 00:29.690
Let me run PHP string manipulation.

00:29.720 --> 00:30.440
There it is.

00:30.440 --> 00:31.700
We've got H.

00:32.840 --> 00:40.340
So using this square bracket syntax you can get specific characters same as in the array.

00:40.340 --> 00:43.460
You can get specific elements from the array.

00:43.490 --> 00:47.450
Next up you can also use negative indexes.

00:48.200 --> 00:57.530
So with this str variable if I output minus one I wonder if you can guess what we're gonna get here.

00:57.650 --> 00:59.000
So let me type that.

00:59.000 --> 01:00.680
And you see this.

01:00.680 --> 01:02.150
The exclamation mark.

01:02.150 --> 01:08.010
So minus one means indexing characters from the end of the string.

01:08.280 --> 01:09.360
So this one.

01:09.900 --> 01:10.590
All right.

01:10.680 --> 01:15.180
Next up, what if you'd like to just grab a part of the string?

01:15.210 --> 01:22.740
Not one character, but maybe a specific amount of characters starting at a specific index.

01:22.770 --> 01:26.970
So there is a function for this called substr.

01:27.000 --> 01:29.340
And you pass a string there.

01:29.370 --> 01:31.650
The starting index.

01:31.920 --> 01:33.660
Um, this starts with zero.

01:33.660 --> 01:37.680
And then optionally the length of characters you want to grab.

01:37.680 --> 01:39.210
If you skip the length.

01:39.240 --> 01:42.810
Everything starting from index will be returned.

01:44.250 --> 01:52.770
So with this string starting from index zero getting five characters, let's see what we're gonna get.

01:52.830 --> 01:56.190
Um, maybe I'm gonna comment out those first.

01:56.220 --> 01:57.420
Let's see.

01:57.780 --> 02:00.180
Um, well, that's.

02:00.180 --> 02:00.600
Hello.

02:00.600 --> 02:02.910
First five characters.

02:03.630 --> 02:14.410
Now, if we're gonna start at index five instead, and we skip the length, well, we're gonna get the

02:14.410 --> 02:16.300
remainder of this string.

02:16.300 --> 02:23.890
So if I comment out this line that's the result of that line.

02:24.100 --> 02:31.750
Now another thing we can do is we can modify the case of the strings.

02:31.750 --> 02:36.910
So str to upper I think we've used this function before.

02:37.660 --> 02:43.390
This will just convert every single character to uppercase like that.

02:43.720 --> 02:49.720
And str to lower will do the opposite.

02:49.750 --> 02:53.200
It will convert everything to lowercase.

02:53.230 --> 02:57.160
Let me comment out those so we can clearly see the output.

02:57.160 --> 02:58.300
There it is.

02:59.350 --> 03:00.880
That was the original.

03:01.420 --> 03:08.740
So if we want to uppercase only the first character we can do you see first.

03:09.280 --> 03:18.340
And if we mix that with str two lower we can only make the first character of the sentence uppercase.

03:18.340 --> 03:21.110
That's also often very useful.

03:22.460 --> 03:24.200
So essentially it looks like this.

03:24.200 --> 03:27.500
Typically you just start a sentence from the uppercase letter.

03:27.500 --> 03:32.030
So this combination is something you actually might be using quite often.

03:32.330 --> 03:34.460
Next up the concatenation.

03:34.460 --> 03:39.680
Let's define a greeting variable that might say hello.

03:39.680 --> 03:41.450
And we've seen that before.

03:41.450 --> 03:45.170
So we use dot operator to concatenate.

03:47.990 --> 03:50.930
I forgot the assignment.

03:51.260 --> 03:53.180
So that's a typical concatenation.

03:53.180 --> 03:54.890
Nothing we haven't done before.

03:54.890 --> 03:58.670
But apart from this you can append something.

03:58.670 --> 04:01.040
So this will be dot equals.

04:01.040 --> 04:05.600
This just means append some text to the variable on the left.

04:06.200 --> 04:11.090
So this would be let's say how are you.

04:11.930 --> 04:17.240
Now let's echo this greeting variable.

04:18.050 --> 04:22.520
So this is PHP string manipulation.

04:24.230 --> 04:26.840
And there we have it.
