PHP similar_text () function
Examples
Compute the similarity of two strings and returns the number of characters matched:
<?php
echo similar_text("Hello World","Hello Peter");
?>
echo similar_text("Hello World","Hello Peter");
?>
Running instance »
Definition and Usage
similar_text () function calculates the similarity between two strings.
This function can also calculate the percentage of similarity between two strings.
Note: the Levenshtein () function than similar_text () function faster.However, similar_text () function provides more accurate results with less number of changes required.
grammar
similar_text( string1,string2,percent )
参数 | 描述 |
---|---|
string1 | 必需。规定要比较的第一个字符串。 |
string2 | 必需。规定要比较的第二个字符串。 |
percent | 可选。规定供存储百分比相似度的变量名。 |
technical details
return value: | Returns the number of characters of two strings match. |
---|---|
PHP version: | 4+ |
More examples
Example 1
Similarity percentage of two strings:
<?php
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>
Running instance »
PHP String Reference