similar_text()

首页 / php / 正文

similar_text()

计算两个字符串的相似度,并返回匹配字符的数目

语法

similar_text($string1, $string2, [$parcent]);

参数

$string1 // 必需,要比较的第一个字符串
$string2 // 必须,要比较的第二个字符串
$parcent // 可选,存储百分比相似度的变量名

返回值

返回两个字符串的匹配字符的数目

实例

计算两个字符串之间的百分比相似度

similar_text('hello', 'hello world', $percent);
echo $perceent.'%';
打赏
评论区
头像