Wednesday, 5 March 2014

String Function

string functions
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):-

php strrev function
Screenshot1


<?php

$string = 'This is an example string .';

 $string_reversed = strrev($string);

 $string_reversed;

 ?>

output (Screenshot2):-

string functions
Screenshot2
In this example i had used function strrev it will reverse the string.

code for the string function similar_text(); (Screenshot3) :-

string functions
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;

?&gt

Output (Screenshot4) :-

String Functions php
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) :-

similar_text() function php
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) :-

php string functions
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 length php
screenshot7


<?php

$string = 'This is an example string.';

 $string_length = strlen($string);

echo string_length;

?>

output screenshot8

string functions
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..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates