Difference between revisions of "PHP-and-MySQL/C4/PHP-String-Functions-Part-1/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
 
|-
 
|-
 
|00:00
 
|00:00
|Welcome to the tutorial on string functions.
+
|Welcome to the tutorial on '''string functions'''.
 
|-
 
|-
 
|00:03
 
|00:03
|I'll take you through the string functions that are shown here.
+
|I'll take you through the '''string functions''' that are shown here.
 
|-
 
|-
 
|00:06
 
|00:06
Line 13: Line 13:
 
|-
 
|-
 
|00:10
 
|00:10
|And also definitely applicable to all the videos I will or have really made.
+
|And also definitely applicable to all the videos I will or have already made.
 
|-
 
|-
 
|00:16
 
|00:16
| Ok,so... the first one I'll show you is "strlen".  
+
| Ok, so... the first one I'll show you is '''strlen()'''.  
 
|-
 
|-
 
|00:20
 
|00:20
|This is extremely simple in which we have a string value of lets say "hello".
+
|This is extremely simple in which we have a '$string' value of let's say "hello".
 
|-
 
|-
 
|00:26
 
|00:26
|Now, this function takes a string and counts the number of characters in that string.
+
|Now, this '''function''' takes a '''string''' and counts the number of characters in that '''string'''.
 
|-
 
|-
 
|00:30
 
|00:30
|So here we've got 1 2 3 4 5 characters.
+
|So, here we've got 1, 2, 3, 4, 5 characters.
 
|-
 
|-
 
|00:35
 
|00:35
|And if we were to echo out the value of the variable string using this function, we should have a result of 5 in our browser.
+
|And if we were to '''echo''' out the value of the variable '$string' using this function, we should have a result of 5 in our browser.
 
|-
 
|-
 
|00:47
 
|00:47
Line 34: Line 34:
 
|-
 
|-
 
|00:52
 
|00:52
|If you were looping through the number of string characters using a 'for' loop, you would need mb substring to take a specific subsstring inside.
+
|If you were looping through the number of '''string''' characters using a '''for''' loop, you would need '''mb substring''' to take a specific 'sub string' inside.
 
|-
 
|-
 
|01:03
 
|01:03
|So, for example if you had the string of, lets say, "My name is Alex",
+
|So, for example if you had the string of, let's say, "My name is Alex"
 
|-
 
|-
 
|01:12
 
|01:12
|And we wanted to loop through this, checking each character as we went...
+
|and we wanted to '''loop''' through this, checking each character as we went...
 
|-
 
|-
 
|01:18
 
|01:18
|For eg- if you check out my 'Name Splitter' tutorial, we loop through each single character until we find a space and then from there on we save the last name.
+
|For e.g.- if you check out my 'Name Splitter' tutorial, we loop through each single character until we find a space and then from there on we save the last name.
 
|-
 
|-
 
|01:32
 
|01:32
|So first, I'll echo out mb substring.
+
|So first, I'll echo out mb_substring().
 
|-
 
|-
 
|01:37
 
|01:37
|And next we will specify the string that we need to check.  
+
|And next, we will specify the '''$string''' that we need to check.  
 
|-
 
|-
 
|01:40
 
|01:40
Line 64: Line 64:
 
|-
 
|-
 
|01:57
 
|01:57
|So what it's done is it's gone through this string and said, "Right, we'll start at zero, and we'll say, for 1, 2, we'll echo out that here.  
+
|So, what it's done is- it's gone through this string and said, "Right, we'll start at zero, and we'll say, for 1, 2, we'll echo out that here.  
 
|-
 
|-
 
|02:05
 
|02:05
|Now what I will do, is say, I will say 's-t-r-len', oh sorry, length equals strlen of string.  
+
|Now what I will do, is say, I will say 's-t-r-len', oh sorry, length equals '''strlen''' of '$string'.  
 
|-
 
|-
 
|02:15
 
|02:15
|I'm creating a new variable here of the length of this string.  
+
|I'm creating a new variable here of the length of this '$string'.  
 
|-
 
|-
 
|02:19
 
|02:19
Line 76: Line 76:
 
|-
 
|-
 
|02:22
 
|02:22
|As long as I start from zero, I can put the string length  in there or rather sorry, length in there and as we refresh we get the whole of the string.  
+
|As long as I start from zero, I can put the string length  in there or rather sorry, '$length' in there and as we refresh we get the whole of the string.  
 
|-
 
|-
 
|02:37
 
|02:37
|And what I could also do, is say s-t-r-len minus 5 on the end here for my name including the full stop - so I'm saying minus 5.  
+
|And what I could also do is, say s-t-r-len minus 5 on the end here for my name including the full stop - so I'm saying minus 5.  
 
|-
 
|-
 
|02:49
 
|02:49
|So that would take five off the length and just echo out "My name is"  
+
|So, that would take five off the length and just echo out "My name is".
 
|-
 
|-
 
|02:53
 
|02:53
Line 88: Line 88:
 
|-
 
|-
 
|02:56
 
|02:56
|So these two functions are quite versatile and using the strlen which applies to mb substring here.
+
|So these two functions are quite versatile and using the '''strlen()''' which applies to '''mb_substring''' here.
 
|-
 
|-
 
|03:03
 
|03:03
|Ok. So the next function I'll go through is 'explode'.  
+
|Ok. So the next function I'll go through is '''explode()'''.  
 
|-
 
|-
 
|03:07
 
|03:07
|Now explode will take a string as we have here  
+
|Now '''explode()''' will take a '''$string''' as we have here.
 
|-
 
|-
 
|03:13
 
|03:13
|Lets just say 1 2 3 4 5  
+
|Let's just say "1 2 3 4 5"
 
|-
 
|-
 
|03:17
 
|03:17
|And the explode function it will echo out explode.   
+
|and the '''explode()''' function it will '''echo''' out '''explode'''.   
 
|-
 
|-
 
|03:23
 
|03:23
Line 106: Line 106:
 
|-
 
|-
 
|03:32
 
|03:32
|So say we want to create and write out this.   
+
|So, say we want to create and write out this.   
 
|-
 
|-
 
|03:35
 
|03:35
|I want 1 2 3 4 5 stored in each separate element of the array.
+
|I want 1 2 3 4 5 stored in each separate element of the '''array'''.
 
|-
 
|-
 
|03:40
 
|03:40
|I'll say explode string. No I'll not - I'll specify what is used to break up the string.
+
|I'll say '''explode''' '''string'''. No I'll not - I'll specify what is used to break up the '''string'''.
 
|-
 
|-
 
|03:45
 
|03:45
|At the moment its the space.   
+
|At the moment it's the '''space'''.   
 
|-
 
|-
 
|03:49
 
|03:49
Line 121: Line 121:
 
|-
 
|-
 
|03:51
 
|03:51
|Because this would be the determinant where it starts
+
|Because this would be the determinant where it starts and this is the separator.   
and this is the separator.   
+
 
|-
 
|-
 
|03:57
 
|03:57
 
|This is the second value.
 
|This is the second value.
So for the moment we will have space. Ok?
+
So, for the moment we will have '''space'''. Ok?
 
|-
 
|-
 
|04:03
 
|04:03
|So you can add anything you want in here.  It can be an asterisk.   
+
|So, you can add anything you want in here.  It can be an asterisk.   
 
|-
 
|-
 
|04:06
 
|04:06
Line 135: Line 134:
 
|-
 
|-
 
|04:11
 
|04:11
|Explode and then the name of the string.
+
|'''explode''' and then the name of the '''string'''.
 
|-
 
|-
 
|04:16
 
|04:16
Line 141: Line 140:
 
|-
 
|-
 
|04:18
 
|04:18
|Lets check that out.
+
|Let's check that out.
 
|-
 
|-
 
|04:20
 
|04:20
Line 147: Line 146:
 
|-
 
|-
 
|04:22
 
|04:22
|Array.  At the moment echoing out the array.
+
|"Array".  At the moment echoing out the array.
 
|-
 
|-
 
|04:26
 
|04:26
Line 153: Line 152:
 
|-
 
|-
 
|04:30
 
|04:30
|We can say it has been set to an array because we've learnt that in my Array tutorial, my basic tutorial.
+
|We can say it has been set to an array because we've learnt that in my Array tutorial  
 
|-
 
|-
 
|04:35
 
|04:35
|And here it tells us we have an array.
+
|and here it tells us we have an array.
 
|-
 
|-
 
|04:37
 
|04:37
|So now if we just use this function on the same and then echo out ...
+
|So, now if we just use this function and then echo out ...
 
|-
 
|-
 
|04:41
 
|04:41
Line 165: Line 164:
 
|-
 
|-
 
|04:44
 
|04:44
|So lets say exp array equals that and then were going to say exp - array and we can echo out numbers.
+
|So let's say, '''$exp array''' equals that and then were going to say '''$exp- array''' and we can '''echo''' out numbers.
 
|-
 
|-
 
|04:52
 
|04:52
Line 174: Line 173:
 
|-
 
|-
 
|05:01
 
|05:01
|So lets say I want to echo out 1 that should equal 2.
+
|So let's say I want to '''echo''' out 1 that should equal 2.
 
|-
 
|-
 
|05:06
 
|05:06
Line 180: Line 179:
 
|-
 
|-
 
|05:09
 
|05:09
|Like I said before we put slashes here and just replace space with slash.
+
|Like I said before, we put slashes here and just replace '''space''' with slash.
 
|-
 
|-
 
|05:16
 
|05:16
Line 186: Line 185:
 
|-
 
|-
 
|05:21
 
|05:21
|Ok? So that's 'explode'.
+
|Ok? So that's '''explode()'''.
 
|-
 
|-
 
|05:23
 
|05:23
|Now the opposite of that is 'implode'.
+
|Now the opposite of that is '''implode()'''.
 
|-
 
|-
 
|05:26
 
|05:26
Line 195: Line 194:
 
|-
 
|-
 
|05:28
 
|05:28
|And you can see the 'implode' function here, also called join.
+
|And you can see the '''implode()''' function here, also called '''join()'''.
 
|-
 
|-
 
|05:32
 
|05:32
|So you can call it as join or implode whatever you prefer.
+
|So you can call it as '''join''' or '''implode''' whatever you prefer.
 
|-
 
|-
 
|05:38
 
|05:38
|So what I'll do is type a new string and its the value of implode and what we're going to implode is our 'exparray'.
+
|So what I'll do is type a '''$new string''' and it's the value of '''implode()''' and what we're going to implode is our '$exparray'.
 
|-
 
|-
 
|05:51
 
|05:51
|Ok so lets try it out.
+
|Ok, so let's try it out.
 
|-
 
|-
 
|05:55
 
|05:55
|Ok we've done that without any errors.
+
|Ok, we've done that without any errors.
 
|-
 
|-
 
|05:57
 
|05:57
|Now if we echo out our new string -  
+
|Now if we '''echo''' out our '''$new string''' -  
 
|-
 
|-
 
|06:01
 
|06:01
|That should recall what we started with before, with no spaces.
+
|that should recall what we started with before, with no '''spaces'''.
 
|-
 
|-
 
|06:05
 
|06:05
Line 219: Line 218:
 
|-
 
|-
 
|06:09
 
|06:09
|So here I decided to add space. But if you wanted slash there you could just put a forward slash here and get that result.
+
|So here I decided to add '''space'''. But if you wanted slash there you could just put a forward slash here and get that result.
 
|-
 
|-
 
|06:21
 
|06:21
Line 225: Line 224:
 
|-
 
|-
 
|06:27
 
|06:27
|So explode and implode. And like we said before this can written as join.  
+
|So '''explode()''' and '''implode()'''. And like we said before this can be written as '''join()'''.  
 
|-
 
|-
 
|06:32
 
|06:32
|So refresh and we get exactly the same result.
+
|So, refresh and we get exactly the same result.
 
|-
 
|-
 
|06:34
 
|06:34
|So that's the 'implode' function there.
+
|So that's the 'implode()' function there.
 
|-
 
|-
 
|06:36
 
|06:36
|Ok - the next function we go to is nl2br.  
+
|Ok - the next function we go to is '''nl2br()'''.  
 
|-
 
|-
 
|06:41
 
|06:41
Line 246: Line 245:
 
|-
 
|-
 
|06:58
 
|06:58
|This 'Hello' or should I say 'Hello', 'New line', 'Another new line' and I'll put the semi-colon that is the line break here  
+
|This 'Hello' or should I say 'Hello', 'New line', 'Another new line' and I'll put the semi-colon that is the line break here.
 
|-
 
|-
 
|07:12
 
|07:12
|Lets keep it as that.
+
|Let's keep it as that.
 
|-
 
|-
 
|07:16
 
|07:16
|Ok so if I echo this out, we can imagine what will happen.
+
|Ok, so if I echo this out, we can imagine what will happen.
 
|-
 
|-
 
|07:19
 
|07:19
Line 261: Line 260:
 
|-
 
|-
 
|07:30
 
|07:30
|So if you don't want to use html for some reason or if you are taking from data base result, you will have to build quite a complex function to put line breaks in it.
+
|So, if you don't want to use html for some reason or if you are taking from data base result, you will have to build quite a complex function to put '''line breaks''' in it.
 
|-
 
|-
 
|07:44
 
|07:44
Line 267: Line 266:
 
|-
 
|-
 
|07:47
 
|07:47
|So if you cannot build and just have this lame test in the database, what you really want to do is just echo out without having to manually use quotes and put breaks in it- if that makes sense.
+
|So, if you cannot build and just have this lame test in the database, what you really want to do is just echo out without having to manually use quotes and put breaks in it- if that makes sense.
 
|-
 
|-
 
|07:59
 
|07:59
|But if you put nl2br at the start of a string and we'll just end the bracket there
+
|But if you put '''nl2br''' at the start of a string and we'll just end the bracket there,
 
|-
 
|-
 
|08:04
 
|08:04
|You'll see it will echo out the exact way we want it to.
+
|you'll see it will echo out the exact way we want it to.
 
|-
 
|-
 
|08:08
 
|08:08
Line 279: Line 278:
 
|-
 
|-
 
|08:16
 
|08:16
|So without nl2br we would get everything in one line and with nl2br we would get separate lines, just the way we want it
+
|So, without '''nl2br''' we would get everything in one line and with '''nl2br''' we would get separate lines, just the way we want it.
 
|-
 
|-
 
|08:30
 
|08:30
|Ok so I'll stop this video here as I'm running out of time. There's a second part for the rest of these functions.  Be sure to catch it.   
+
|Ok, so I'll stop this video here as I'm running out of time. There's a second part for the rest of these functions.  Be sure to catch it.   
 
|-
 
|-
 
|08:38
 
|08:38
|See you soon.  This is Osama Butt dubbing for the Spoken Tutorial Project.
+
|See you soon.  This is Osama Butt, dubbing for the Spoken Tutorial Project.

Latest revision as of 22:26, 2 June 2015

Time Narration
00:00 Welcome to the tutorial on string functions.
00:03 I'll take you through the string functions that are shown here.
00:06 Most of them are very useful and applicable to everyday applications.
00:10 And also definitely applicable to all the videos I will or have already made.
00:16 Ok, so... the first one I'll show you is strlen().
00:20 This is extremely simple in which we have a '$string' value of let's say "hello".
00:26 Now, this function takes a string and counts the number of characters in that string.
00:30 So, here we've got 1, 2, 3, 4, 5 characters.
00:35 And if we were to echo out the value of the variable '$string' using this function, we should have a result of 5 in our browser.
00:47 Now, the next function is applicable to this.
00:52 If you were looping through the number of string characters using a for loop, you would need mb substring to take a specific 'sub string' inside.
01:03 So, for example if you had the string of, let's say, "My name is Alex"
01:12 and we wanted to loop through this, checking each character as we went...
01:18 For e.g.- if you check out my 'Name Splitter' tutorial, we loop through each single character until we find a space and then from there on we save the last name.
01:32 So first, I'll echo out mb_substring().
01:37 And next, we will specify the $string that we need to check.
01:40 You need to specify the starting point so I'll say 1.
01:45 In fact, I'll say zero and then the length - I'll say 2.
01:49 And this should echo out "My".
01:52 Refresh. Ok. We've got "My" there.
01:57 So, what it's done is- it's gone through this string and said, "Right, we'll start at zero, and we'll say, for 1, 2, we'll echo out that here.
02:05 Now what I will do, is say, I will say 's-t-r-len', oh sorry, length equals strlen of '$string'.
02:15 I'm creating a new variable here of the length of this '$string'.
02:19 And then I'll replace 2 with this value.
02:22 As long as I start from zero, I can put the string length in there or rather sorry, '$length' in there and as we refresh we get the whole of the string.
02:37 And what I could also do is, say s-t-r-len minus 5 on the end here for my name including the full stop - so I'm saying minus 5.
02:49 So, that would take five off the length and just echo out "My name is".
02:53 Refresh and we get 'My name is'.
02:56 So these two functions are quite versatile and using the strlen() which applies to mb_substring here.
03:03 Ok. So the next function I'll go through is explode().
03:07 Now explode() will take a $string as we have here.
03:13 Let's just say "1 2 3 4 5"
03:17 and the explode() function it will echo out explode.
03:23 It will break your string, a plain string. From the start to the finish, it will break it down into an array.
03:32 So, say we want to create and write out this.
03:35 I want 1 2 3 4 5 stored in each separate element of the array.
03:40 I'll say explode string. No I'll not - I'll specify what is used to break up the string.
03:45 At the moment it's the space.
03:49 If we had slash, we would replace it by slash.
03:51 Because this would be the determinant where it starts and this is the separator.
03:57 This is the second value.

So, for the moment we will have space. Ok?

04:03 So, you can add anything you want in here. It can be an asterisk.
04:06 It can be any symbol really. You just need to specify what breaks up the string.
04:11 explode and then the name of the string.
04:16 And that should be it.
04:18 Let's check that out.
04:20 Refresh.
04:22 "Array". At the moment echoing out the array.
04:26 Obviously you can see that what I have done is just echoed out an array.
04:30 We can say it has been set to an array because we've learnt that in my Array tutorial
04:35 and here it tells us we have an array.
04:37 So, now if we just use this function and then echo out ...
04:41 In fact, we need to first set this to a variable.
04:44 So let's say, $exp array equals that and then were going to say $exp- array and we can echo out numbers.
04:52 We can use zero, one, two, three, four and that would be it.
04:56 So as soon as this value is zero, this would equal 1.
05:01 So let's say I want to echo out 1 that should equal 2.
05:06 Okay, so we've successfully broken our array.
05:09 Like I said before, we put slashes here and just replace space with slash.
05:16 And we'll have exactly the same result here.
05:21 Ok? So that's explode().
05:23 Now the opposite of that is implode().
05:26 Let me get rid of this.
05:28 And you can see the implode() function here, also called join().
05:32 So you can call it as join or implode whatever you prefer.
05:38 So what I'll do is type a $new string and it's the value of implode() and what we're going to implode is our '$exparray'.
05:51 Ok, so let's try it out.
05:55 Ok, we've done that without any errors.
05:57 Now if we echo out our $new string -
06:01 that should recall what we started with before, with no spaces.
06:05 But what can be done is you can specify with what to break up your array.
06:09 So here I decided to add space. But if you wanted slash there you could just put a forward slash here and get that result.
06:21 But coming back these functions are for converting 'to' and 'from' arrays.
06:27 So explode() and implode(). And like we said before this can be written as join().
06:32 So, refresh and we get exactly the same result.
06:34 So that's the 'implode()' function there.
06:36 Ok - the next function we go to is nl2br().
06:41 Now this function is really functional and easy when we are working with data bases.
06:46 When data is being stored on an immediate-line-basis.
06:51 Now remember I said that if you had watched my basic tutorials you would've known that...
06:58 This 'Hello' or should I say 'Hello', 'New line', 'Another new line' and I'll put the semi-colon that is the line break here.
07:12 Let's keep it as that.
07:16 Ok, so if I echo this out, we can imagine what will happen.
07:19 We will get this.
07:21 If we want them on separate lines then we should use 'br'.
07:30 So, if you don't want to use html for some reason or if you are taking from data base result, you will have to build quite a complex function to put line breaks in it.
07:44 It happens when people set me in to a data base.
07:47 So, if you cannot build and just have this lame test in the database, what you really want to do is just echo out without having to manually use quotes and put breaks in it- if that makes sense.
07:59 But if you put nl2br at the start of a string and we'll just end the bracket there,
08:04 you'll see it will echo out the exact way we want it to.
08:08 We'll get a line break at the top because we have done this - added a space here. Let's remove that.
08:16 So, without nl2br we would get everything in one line and with nl2br we would get separate lines, just the way we want it.
08:30 Ok, so I'll stop this video here as I'm running out of time. There's a second part for the rest of these functions. Be sure to catch it.
08:38 See you soon. This is Osama Butt, dubbing for the Spoken Tutorial Project.

Contributors and Content Editors

Gaurav, Gyan, PoojaMoolya, Sandhya.np14