Sunday, 20 October 2013

String Function part - 3

String Functions in Php
String function in php programming langauges. This is tutorial forstring function part 3. In this tutorial i am going to show you functionof the string let see example
Code for the string function strrev(); (Screenshot1):-
String function in php
String function part – 3 (Screenshot1)
1
2
3
4
5
6
7
<?php
$string = 'This is an example string .';
 $string_reversed = strrev($string);
<span id="IL_AD8" class="IL_AD">echo</span> $string_reversed;
 ?>
output (Screenshot2):-
String function in php
String function part – 3 (Screenshot2)
In this example i had used function strrev it will reverse the string.
code for the string function similar_text(); (Screenshot3) :-
String function in php
String function part – 3 (Screenshot3)
1
2
3
4
5
6
7
8
9
<?php
$string_one = 'This is my essay. I\'m going to be talking about php.';
 $string_two = 'This is my essay. I will be talking about the subject php.';
similar_text($string_one, $string_two, $result);
 echo 'The similarity between is,'.$result;
?>
Output (Screenshot4) :-
String function in php
String function part – 3 (Screenshot4)
In this example we will see similar_text(); string function which is used to find the similarity between two variables or paragraph whatever you take. It will echo the result in percentage who much words are repeated in both paragraph in percentage as you seenexample i had two variables such as string_one and string two now similar_text had three arguments such as variable one and secondvariable for comparing both of them and the third variable to store the percentage of similar data. You can use this function when you are writing essay and want to calculate two essay similarity between them in percentage.
code for the string function similar_text(); (Screenshot5) :-
String function in php
String function part – 3 (Screenshot5)
1
2
3
4
5
6
7
8
9
<?php
$string_one = 'This is my essay. I\'m going to be talking about php.';
 $string_two = 'My essay is about php. I\'m going to be talking about everything to do with php.';
similar_text($string_one, $string_two, $result);
 echo 'The similarity between is,'.$result;
?>
Output (Screenshot6) :-
String function in php
String Function part – 3 (Screenshot6 )
In this example i had changed variable to different words and you can see output difference in screenshot4 and screenshot6.
Code for the string function strlen(); (Screenshot7) :-
String function in php
String Function part – 3 (Screenshot7)
1
2
3
4
5
6
7
8
<?php
$string = 'This is an example string.';
 $string_length = strlen($string);
echo string_length;
?>
Output (Screenshot8):-
String function in php
String Function part – 3 (Screenshot8)
In this example strlen in string function is used for count the stringlength as u can see the example this function is very useful in validation code. for username is not more then 25 characters so, you can find the inputted length by using this function of the user.
Try Other String function for Yourself :-
trim();
ltrim();
rtrim();
addslashed();
strip_slashes();

Read More On Extra Tutorials

No comments:

Post a Comment