Home >>PHP String Functions >PHP similar_text() Function
PHP similar_text() function is used to calculate the similarity between two given input strings. This function returns the number of matching characters in the both input strings as the output. This function is also used to calculate the similarity of the strings in percent.
Syntax:
similar_text($string1,$string2,$percent);
Parameter | Description |
---|---|
string1 | This is a required parameter. This parameter contains the first string to be compared. |
string2 | This is a required parameter. This parameter contains the second string to be compared. |
percent | This is an optional parameter. This parameter contains a variable name for storing the similarity in percent. |
Here is an example of similar_text() function in PHP:
<html> <body> <?php echo similar_text("PHP","PHPTPOINT"); ?> </body> </html>
Here is an another example of similar_text() function in PHP:
<html> <body> <?php $str1 ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $str2= "ABHI"; echo similar_text("$str1","$str2"); ?> </body> </html>
Here is another example of similar_text() function in PHP using the $percent parameter:
<html> <body> <?php similar_text("abcdefghijkl","asdfghjkl",$percent); echo $percent; ?> </body> </html>