Home >Backend Development >PHP Tutorial >php similar_text(), phpsimilar_text_PHP tutorial
php similar_text() function calculates and compares the similarity of two strings. This article introduces the basic use of php similar_text() function to coders. Interested programmers can refer to the methods and basic usage examples.
The similar_text() function calculates the similarity of two strings.
This function can also calculate the percentage similarity of two strings.
Note: levenshtein() function is faster than similar_text() function. However, the similar_text() function provides more accurate results with fewer modifications required.
similar_text(string1,string2,percent)
参数 | 描述 |
---|---|
string1 | 必需。规定要比较的第一个字符串。 |
string2 | 必需。规定要比较的第二个字符串。 |
percent | 可选。规定供存储百分比相似度的变量名。 |
返回值: | 返回两个字符串的匹配字符的数目。 |
PHP 版本: | 4 |
Calculate the percentage similarity between two strings:
<?<span>php </span><span>similar_text</span>("Hello World","Hello Shanghai",<span>$percent</span><span>); </span><span>echo</span> <span>$percent</span>. "%"<span>; </span>?>
Run online
Original address: http://www.manongjc.com/article/805.html
php related learning: