The similar_text() function calculates the similarity between two strings.
PHP similar_text() Function has the following syntax.
similar_text(string1,string2,percent)
Parameter | Is Required | Description |
---|---|---|
string1 | Required. | First string to be compared |
string2 | Required. | Second string to be compared |
percent | Optional. | Variable name for storing the similarity in percent |
PHP similar_text() Function returns the number of matching characters of two strings.
Calculate the similarity between two strings and return the matching characters:
<?php
echo similar_text("Hello World","Hello from java2s.com");
?>
The code above generates the following result.
Calculate the similarity between two strings in percent:
<?php
similar_text("Hello World","Hello from java2s.com",$percent);
echo $percent;
?>
The code above generates the following result.