This article mainly introduces the syntax and usage of similar text function in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.
1, usage of similar_text
If I want to calculate the similarity between "ly89cn" and "ly89", there are two ways to express it
echo similar_text('ly89cn', 'ly89');
similar_text('ly89cn', 'ly89', $percent); echo $percent;
echo similar_text('王业楼的个人博客', '王业楼'); 这样输出9,表示他们的9个字节数相等
similar_text('Wang Yelou's personal blog', 'Wang Yelou', $percent);
echo $percent;
PHP similar_text() function
Example
Calculate the similarity of two strings and return the matching character Number:<?php echo similar_text("Hello World","Hello Shanghai"); ?>
Definition and usage
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. Grammarsimilar_text(string1,string2,percent)
参数 | 描述 |
---|---|
string1 | 必需。规定要比较的第一个字符串。 |
string2 | 必需。规定要比较的第二个字符串。 |
percent | 可选。规定供存储百分比相似度的变量名。 |
Technical details
Return value: | Returns the number of matching characters in the two strings. |
PHP version: | 4 |
similar_text("Hello World","Hello Shanghai",$percent);
echo $percent. "%";
?>
Five PHP methods for reading file content
PHP function to convert Chinese characters into pinyin
PHP jpgraph installation and basic usage
The above is the detailed content of Similar text function syntax and usage in PHP. For more information, please follow other related articles on the PHP Chinese website!