Calculate the similarity between two strings and return the matching characters:
<?php
echo similar_text("Hello World","Hello Peter");
?>
Try it Yourself »
The similar_text() function calculates the similarity between two strings.
It can also calculate the similarity of the two strings in percent.
Note: The levenshtein() function is faster than the similar_text() function. However, the similar_text() function will give you a more accurate result with less modifications needed.
similar_text(
string1,string2,percent)
Parameter | Description |
---|---|
string1 | Required. Specifies the first string to be compared |
string2 | Required. Specifies the second string to be compared |
percent | Optional. Specifies a variable name for storing the similarity in percent |
Return Value: | Returns the number of matching characters of two strings |
---|---|
PHP Version: | 4+ |
Calculate the similarity between two strings in percent:
<?php
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!