String function in php programming languages. This is tutorial for string function part 3. In this tutorial i am going to show you function of the string let see example
Code for the string function strrev(); (Screenshot1):-
Screenshot1 |
<?php $string = 'This is an example string .'; $string_reversed = strrev($string); $string_reversed; ?>
output (Screenshot2):-
Screenshot2 |
In this example i had used function strrev it will reverse the string.
code for the string function similar_text(); (Screenshot3) :-
Screenshot3 |
<?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) :-
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 seen example i had two variables such as string_one and string two now similar_text had three arguments such as variable one and second variable 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) :-
Screenshot4 |
<?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) :-
Screenshot6 |
Code for the string function strlen(); (Screenshot7) :-
screenshot7 |
<?php $string = 'This is an example string.'; $string_length = strlen($string); echo string_length; ?>
output screenshot8
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();
No comments:
Post a Comment
Thanks For Comment Will get you Soon..