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

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{|Border=1 !Time !Narration |- |0:00 |Ok back to the second part of the String Functions tutorial. |- |0:03 |I'm going to go through the rest of the functions starting from Strin…')
 
Line 1: Line 1:
 
{|Border=1
 
{|Border=1
!Time
+
|'''Time'''
!Narration
+
|'''Narration'''
 
|-
 
|-
|0:00
+
|00:00
 
|Ok back to the second part of the String Functions tutorial.
 
|Ok back to the second part of the String Functions tutorial.
 
|-
 
|-
|0:03
+
|00:03
 
|I'm going to go through the rest of the functions starting from String Reverse.
 
|I'm going to go through the rest of the functions starting from String Reverse.
 
|-
 
|-
|0:08
+
|00:08
 
|String reverse probably to make sense is s-t-r-rev.
 
|String reverse probably to make sense is s-t-r-rev.
 
|-
 
|-
|0:11
+
|00:11
 
|So what strvev does is it reverses the contents of a string.
 
|So what strvev does is it reverses the contents of a string.
 
|-
 
|-
|0:20
+
|00:20
 
|So if I were to say 'Hello' and I were to reverse that, it would be "o-l-l-e-H".
 
|So if I were to say 'Hello' and I were to reverse that, it would be "o-l-l-e-H".
 
|-
 
|-
|0:30
+
|00:30
 
|And it can be useful in some circumstances although you usually wouldn't use this.
 
|And it can be useful in some circumstances although you usually wouldn't use this.
 
|-
 
|-
|0:36
+
|00:36
 
|But you could use this function if you want to specifically reverse a string.
 
|But you could use this function if you want to specifically reverse a string.
 
|-
 
|-
|0:41
+
|00:41
 
|I think its a useful and fun function to use.
 
|I think its a useful and fun function to use.
 
|-
 
|-
|0:45
+
|00:45
 
|Ok - the next set of functions I have grouped together are these: str to lower and str to upper.
 
|Ok - the next set of functions I have grouped together are these: str to lower and str to upper.
 
|-
 
|-
|0:54
+
|00:54
 
|This basically means string to lower case and string to upper case.
 
|This basically means string to lower case and string to upper case.
 
|-
 
|-
|0:58
+
|00:58
 
|So if we have our string that equals 'HELLO', I can say echo str to lower and show the value of the string in there.
 
|So if we have our string that equals 'HELLO', I can say echo str to lower and show the value of the string in there.
 
|-
 
|-
|1:12
+
|01:12
 
|The 'HELLO' in capitals will now become lowercase.
 
|The 'HELLO' in capitals will now become lowercase.
 
|-
 
|-
|1:15
+
|01:15
 
|Something similar would happen if I were to say this is 'hello' in smallcase
 
|Something similar would happen if I were to say this is 'hello' in smallcase
 
|-
 
|-
|1:21
+
|01:21
 
|And I could say str to upper and that would give me my uppercase version of the string.
 
|And I could say str to upper and that would give me my uppercase version of the string.
 
|-
 
|-
|1:31
+
|01:31
 
|Now one applicable use of this is when you have user-registration.
 
|Now one applicable use of this is when you have user-registration.
 
|-
 
|-
|1:35
+
|01:35
 
|If you have a website on which users have to register, you should usually always store the user name as a lower string.
 
|If you have a website on which users have to register, you should usually always store the user name as a lower string.
 
|-
 
|-
|1:49
+
|01:49
 
|The reason is that if I submit a user name - lets get rid of this...
 
|The reason is that if I submit a user name - lets get rid of this...
 
|-
 
|-
|1:55
+
|01:55
 
|Some people actually do this - Lets have a variable user name which equals say 'ALEX'.
 
|Some people actually do this - Lets have a variable user name which equals say 'ALEX'.
 
|-
 
|-
|2:01
+
|02:01
 
|And I'll put in these also - uppercase and smallcase alphabets.
 
|And I'll put in these also - uppercase and smallcase alphabets.
 
|-
 
|-
|2:07
+
|02:07
 
|Some people use names like this to  make the name look funky and its perfectly okay.
 
|Some people use names like this to  make the name look funky and its perfectly okay.
 
|-
 
|-
|2:13
+
|02:13
 
|But if the name is stored as this and you think - well did i start with a small a?   
 
|But if the name is stored as this and you think - well did i start with a small a?   
 
|-
 
|-
|2:19
+
|02:19
 
|Then I have another pattern for username now.
 
|Then I have another pattern for username now.
 
|-
 
|-
|2:23
+
|02:23
 
|So what you can do is say stored user name equals to str to lower of the username.
 
|So what you can do is say stored user name equals to str to lower of the username.
 
|-
 
|-
|2:29
+
|02:29
 
|So this would be the stored username in the database  
 
|So this would be the stored username in the database  
 
|-
 
|-
|2:33
+
|02:33
 
|Now when they go to login and type in their username in this combination, what we would do is we would convert their typed-in login username to lower case and compare it to the lower case store version of the username.
 
|Now when they go to login and type in their username in this combination, what we would do is we would convert their typed-in login username to lower case and compare it to the lower case store version of the username.
 
|-
 
|-
|2:48
+
|02:48
 
|So we are taking this and storing a lowercase value inside the database and we are comparing it to a typed-in value which has also been converted to lower case
 
|So we are taking this and storing a lowercase value inside the database and we are comparing it to a typed-in value which has also been converted to lower case
 
|-
 
|-
|2:58
+
|02:58
 
|Hence we can't go wrong and users are not going to forget their user-names.
 
|Hence we can't go wrong and users are not going to forget their user-names.
 
|-
 
|-
|3:07
+
|03:07
 
|You could do the same with passwords.
 
|You could do the same with passwords.
 
|-
 
|-
|3:14
+
|03:14
 
|Ok lets go to the next one.  
 
|Ok lets go to the next one.  
 
|-
 
|-
|3:22
+
|03:22
 
|Sub-string count. This would basically count the no. of sub-strings matching to a particular value inside a string.
 
|Sub-string count. This would basically count the no. of sub-strings matching to a particular value inside a string.
 
|-
 
|-
|3:31
+
|03:31
 
|So here I'll type search equals "My name is alex. What is your name?"
 
|So here I'll type search equals "My name is alex. What is your name?"
 
|-
 
|-
|3:37
+
|03:37
 
|So this is our string.
 
|So this is our string.
 
|-
 
|-
|3:41
+
|03:41
 
|Now if I say we need to echo out the sub-string count...
 
|Now if I say we need to echo out the sub-string count...
 
|-
 
|-
|3:49
+
|03:49
 
|and obviously this stands for sub-string-count, what we want to do is, we want to search our 'search' string...
 
|and obviously this stands for sub-string-count, what we want to do is, we want to search our 'search' string...
 
|-
 
|-
|4:01
+
|04:01
 
|and we will specify a string to search for.  Now this will return an integer if we put this in a variable called result.
 
|and we will specify a string to search for.  Now this will return an integer if we put this in a variable called result.
 
|-
 
|-
|4:12
+
|04:12
 
|That's because you can't find any instance of a word which will appear say for 1.2 times.
 
|That's because you can't find any instance of a word which will appear say for 1.2 times.
 
|-
 
|-
|4:20
+
|04:20
 
|Also the variable result will not return 2 as t-w-o.  It will only return 2 as an integer.
 
|Also the variable result will not return 2 as t-w-o.  It will only return 2 as an integer.
 
|-
 
|-
|4:30
+
|04:30
 
|So this is quite useful if we are using substring count to search for, lets say, 'alex'.
 
|So this is quite useful if we are using substring count to search for, lets say, 'alex'.
 
|-
 
|-
|4:36
+
|04:36
 
|And then it will echo out on its own.
 
|And then it will echo out on its own.
 
|-
 
|-
|4:39
+
|04:39
 
|And if you look through here, you will see there is only one instance of 'alex'
 
|And if you look through here, you will see there is only one instance of 'alex'
 
|-
 
|-
|4:44
+
|04:44
 
|So refresh that - and we should get the number 1.
 
|So refresh that - and we should get the number 1.
 
|-
 
|-
|4:46
+
|04:46
 
|Now if we were to search for 'name' - there's 1 instance of 'name' here and another instance of 'name' here  
 
|Now if we were to search for 'name' - there's 1 instance of 'name' here and another instance of 'name' here  
 
|-
 
|-
|4:52
+
|04:52
 
|So when we refresh, we should get the value 2.
 
|So when we refresh, we should get the value 2.
 
|-
 
|-
|4:55
+
|04:55
 
|Now there are optional parameters for this, which are 'where to start from in a string' and 'where to end in a string'.
 
|Now there are optional parameters for this, which are 'where to start from in a string' and 'where to end in a string'.
 
|-
 
|-
|5:02
+
|05:02
 
|Lets try this out.
 
|Lets try this out.
 
|-
 
|-
|5:05
+
|05:05
 
|So lets say I want to search from after name, ok?
 
|So lets say I want to search from after name, ok?
 
|-
 
|-
|5:11
+
|05:11
 
|So this is 0 1 2 3 4 5 6.
 
|So this is 0 1 2 3 4 5 6.
 
|-
 
|-
|5:14
+
|05:14
 
|So I say search name from 7 onwards.
 
|So I say search name from 7 onwards.
 
|-
 
|-
|5:19
+
|05:19
 
|So search name from 7 and it will search in this blue area that I have highlighted here.
 
|So search name from 7 and it will search in this blue area that I have highlighted here.
 
|-
 
|-
|5:25
+
|05:25
 
|It will only return 1 in the result.
 
|It will only return 1 in the result.
 
|-
 
|-
|5:28
+
|05:28
 
|So you can specify whereabouts in the string.
 
|So you can specify whereabouts in the string.
 
|-
 
|-
|5:30
+
|05:30
 
|I think you can specify upto where.   
 
|I think you can specify upto where.   
 
|-
 
|-
|5:33
+
|05:33
 
|So this is 7... 8 9 10 11 12 13 14 15 16.  
 
|So this is 7... 8 9 10 11 12 13 14 15 16.  
 
|-
 
|-
|5:43
+
|05:43
 
|7 to 17.  Lets check if this works.
 
|7 to 17.  Lets check if this works.
 
|-
 
|-
|5:46
+
|05:46
 
|It shows zero.  So from 7 to 17 - which is from about here to here - we find zero instances of 'name'.  
 
|It shows zero.  So from 7 to 17 - which is from about here to here - we find zero instances of 'name'.  
 
|-
 
|-
|5:55
+
|05:55
 
|However if we search for 'alex', we will find 1 instance of it.
 
|However if we search for 'alex', we will find 1 instance of it.
 
|-
 
|-
|6:01
+
|06:01
 
|Ok - so that's the substring count function.
 
|Ok - so that's the substring count function.
 
|-
 
|-
|6:07
+
|06:07
 
|And now substring replace is similar.
 
|And now substring replace is similar.
 
|-
 
|-
|6:12
+
|06:12
 
|Its not the same function but it includes an added bonus where you can replace your string.
 
|Its not the same function but it includes an added bonus where you can replace your string.
 
|-
 
|-
|6:18
+
|06:18
 
|So the replace tags are - My name is alex and I've added the full-stop on purpose.
 
|So the replace tags are - My name is alex and I've added the full-stop on purpose.
 
|-
 
|-
|6:28
+
|06:28
 
|Our result is equal to substring replace.
 
|Our result is equal to substring replace.
 
|-
 
|-
|6:33
+
|06:33
 
|What do I want to replace in? I want to replace in the variable replace.
 
|What do I want to replace in? I want to replace in the variable replace.
 
|-
 
|-
|6:41
+
|06:41
 
|And I want to replace 'alex' with 'billy'.
 
|And I want to replace 'alex' with 'billy'.
 
|-
 
|-
|6:48
+
|06:48
 
|And this will be from - let me count 0 1 2 3 4 5  7 8 9 10 11 so from 11 until...
 
|And this will be from - let me count 0 1 2 3 4 5  7 8 9 10 11 so from 11 until...
 
|-
 
|-
|7:01
+
|07:01
 
|Its 11 - 0 1 2 3 4 5 6 7 8 9 10 11  - from 11 to 14.  
 
|Its 11 - 0 1 2 3 4 5 6 7 8 9 10 11  - from 11 to 14.  
 
|-
 
|-
|7:14
+
|07:14
 
|So that should replace 'alex' with 'billy'.
 
|So that should replace 'alex' with 'billy'.
 
|-
 
|-
|7:19
+
|07:19
 
|Replace and refresh.
 
|Replace and refresh.
 
|-
 
|-
|7:21
+
|07:21
 
|Oh! We didn't echo out result.
 
|Oh! We didn't echo out result.
 
|-
 
|-
|7:23
+
|07:23
 
|Lets echo out result and we can refresh this.
 
|Lets echo out result and we can refresh this.
 
|-
 
|-
|7:26
+
|07:26
 
|And it should return my name is billy.
 
|And it should return my name is billy.
 
|-
 
|-
|7:30
+
|07:30
 
|This should be 12 and this 15, I think.
 
|This should be 12 and this 15, I think.
 
|-
 
|-
|7:34
+
|07:34
 
|Or in fact no - it should be 10 and 14.
 
|Or in fact no - it should be 10 and 14.
 
|-
 
|-
|7:38
+
|07:38
 
|No, not quite right.... We are missing the full-stop.
 
|No, not quite right.... We are missing the full-stop.
 
|-
 
|-
|7:43
+
|07:43
 
|........ so lets go for 11 and 14.
 
|........ so lets go for 11 and 14.
 
|-
 
|-
|7:49
+
|07:49
 
|Still missing the full stop and I cant think why.
 
|Still missing the full stop and I cant think why.
 
|-
 
|-
|7:52
+
|07:52
 
|aah! well you get the picture
 
|aah! well you get the picture
 
|-
 
|-
|7:55
+
|07:55
 
|Basically you can replace anything in the string with the starting value and the ending value  
 
|Basically you can replace anything in the string with the starting value and the ending value  
 
|-
 
|-
|7:59
+
|07:59
 
|It will leave it up to you to count through.
 
|It will leave it up to you to count through.
 
|-
 
|-
|8:04
+
|08:04
 
|I'm very tired so I am not able to count.
 
|I'm very tired so I am not able to count.
 
|-
 
|-
|8:09
+
|08:09
 
|So what we are doing here is we are replacing a particular string with a particular value
 
|So what we are doing here is we are replacing a particular string with a particular value
 
|-
 
|-
|8:14
+
|08:14
 
|And here's your starting value and here's your finishing value.
 
|And here's your starting value and here's your finishing value.
 
|-
 
|-
|8:17
+
|08:17
 
|That's all in this tutorial.
 
|That's all in this tutorial.
 
|-
 
|-
|8:19
+
|08:19
 
|There are many more string functions and I suggest you to search, may be, on 'google'.
 
|There are many more string functions and I suggest you to search, may be, on 'google'.
 
|-
 
|-
|8:24
+
|08:24
 
|Search for 'php string functions' and you'll find a lot of interesting functions.
 
|Search for 'php string functions' and you'll find a lot of interesting functions.
 
|-
 
|-
|8:28
+
|08:28
 
|If you are looking to do a particular thing there's probably a function available for it.
 
|If you are looking to do a particular thing there's probably a function available for it.
 
|-
 
|-
|8:33
+
|08:33
 
|Thanks for watching!  This is Osama Butt dubbing for the Spoken Tutorial Project.
 
|Thanks for watching!  This is Osama Butt dubbing for the Spoken Tutorial Project.

Revision as of 12:37, 10 July 2014

Time Narration
00:00 Ok back to the second part of the String Functions tutorial.
00:03 I'm going to go through the rest of the functions starting from String Reverse.
00:08 String reverse probably to make sense is s-t-r-rev.
00:11 So what strvev does is it reverses the contents of a string.
00:20 So if I were to say 'Hello' and I were to reverse that, it would be "o-l-l-e-H".
00:30 And it can be useful in some circumstances although you usually wouldn't use this.
00:36 But you could use this function if you want to specifically reverse a string.
00:41 I think its a useful and fun function to use.
00:45 Ok - the next set of functions I have grouped together are these: str to lower and str to upper.
00:54 This basically means string to lower case and string to upper case.
00:58 So if we have our string that equals 'HELLO', I can say echo str to lower and show the value of the string in there.
01:12 The 'HELLO' in capitals will now become lowercase.
01:15 Something similar would happen if I were to say this is 'hello' in smallcase
01:21 And I could say str to upper and that would give me my uppercase version of the string.
01:31 Now one applicable use of this is when you have user-registration.
01:35 If you have a website on which users have to register, you should usually always store the user name as a lower string.
01:49 The reason is that if I submit a user name - lets get rid of this...
01:55 Some people actually do this - Lets have a variable user name which equals say 'ALEX'.
02:01 And I'll put in these also - uppercase and smallcase alphabets.
02:07 Some people use names like this to make the name look funky and its perfectly okay.
02:13 But if the name is stored as this and you think - well did i start with a small a?
02:19 Then I have another pattern for username now.
02:23 So what you can do is say stored user name equals to str to lower of the username.
02:29 So this would be the stored username in the database
02:33 Now when they go to login and type in their username in this combination, what we would do is we would convert their typed-in login username to lower case and compare it to the lower case store version of the username.
02:48 So we are taking this and storing a lowercase value inside the database and we are comparing it to a typed-in value which has also been converted to lower case
02:58 Hence we can't go wrong and users are not going to forget their user-names.
03:07 You could do the same with passwords.
03:14 Ok lets go to the next one.
03:22 Sub-string count. This would basically count the no. of sub-strings matching to a particular value inside a string.
03:31 So here I'll type search equals "My name is alex. What is your name?"
03:37 So this is our string.
03:41 Now if I say we need to echo out the sub-string count...
03:49 and obviously this stands for sub-string-count, what we want to do is, we want to search our 'search' string...
04:01 and we will specify a string to search for. Now this will return an integer if we put this in a variable called result.
04:12 That's because you can't find any instance of a word which will appear say for 1.2 times.
04:20 Also the variable result will not return 2 as t-w-o. It will only return 2 as an integer.
04:30 So this is quite useful if we are using substring count to search for, lets say, 'alex'.
04:36 And then it will echo out on its own.
04:39 And if you look through here, you will see there is only one instance of 'alex'
04:44 So refresh that - and we should get the number 1.
04:46 Now if we were to search for 'name' - there's 1 instance of 'name' here and another instance of 'name' here
04:52 So when we refresh, we should get the value 2.
04:55 Now there are optional parameters for this, which are 'where to start from in a string' and 'where to end in a string'.
05:02 Lets try this out.
05:05 So lets say I want to search from after name, ok?
05:11 So this is 0 1 2 3 4 5 6.
05:14 So I say search name from 7 onwards.
05:19 So search name from 7 and it will search in this blue area that I have highlighted here.
05:25 It will only return 1 in the result.
05:28 So you can specify whereabouts in the string.
05:30 I think you can specify upto where.
05:33 So this is 7... 8 9 10 11 12 13 14 15 16.
05:43 7 to 17. Lets check if this works.
05:46 It shows zero. So from 7 to 17 - which is from about here to here - we find zero instances of 'name'.
05:55 However if we search for 'alex', we will find 1 instance of it.
06:01 Ok - so that's the substring count function.
06:07 And now substring replace is similar.
06:12 Its not the same function but it includes an added bonus where you can replace your string.
06:18 So the replace tags are - My name is alex and I've added the full-stop on purpose.
06:28 Our result is equal to substring replace.
06:33 What do I want to replace in? I want to replace in the variable replace.
06:41 And I want to replace 'alex' with 'billy'.
06:48 And this will be from - let me count 0 1 2 3 4 5 7 8 9 10 11 so from 11 until...
07:01 Its 11 - 0 1 2 3 4 5 6 7 8 9 10 11 - from 11 to 14.
07:14 So that should replace 'alex' with 'billy'.
07:19 Replace and refresh.
07:21 Oh! We didn't echo out result.
07:23 Lets echo out result and we can refresh this.
07:26 And it should return my name is billy.
07:30 This should be 12 and this 15, I think.
07:34 Or in fact no - it should be 10 and 14.
07:38 No, not quite right.... We are missing the full-stop.
07:43 ........ so lets go for 11 and 14.
07:49 Still missing the full stop and I cant think why.
07:52 aah! well you get the picture
07:55 Basically you can replace anything in the string with the starting value and the ending value
07:59 It will leave it up to you to count through.
08:04 I'm very tired so I am not able to count.
08:09 So what we are doing here is we are replacing a particular string with a particular value
08:14 And here's your starting value and here's your finishing value.
08:17 That's all in this tutorial.
08:19 There are many more string functions and I suggest you to search, may be, on 'google'.
08:24 Search for 'php string functions' and you'll find a lot of interesting functions.
08:28 If you are looking to do a particular thing there's probably a function available for it.
08:33 Thanks for watching! This is Osama Butt dubbing for the Spoken Tutorial Project.

Contributors and Content Editors

Gyan, Pratik kamble, Sandhya.np14