[人名] 利文;[地名] [英国] 利文

php levenshtein()函数 语法

作用:计算两个字符串之间的编辑距离

语法:int levenshtein ( string $str1 , string $str2 , int $cost_ins , int $cost_rep , int $cost_del )

参数:

参数描述
str1 求编辑距离中的其中一个字符串。
str2  求编辑距离中的另一个字符串。
cost_ins定义插入次数。
cost_rep  定义替换次数。
cost_del 定义删除次数

说明:编辑距离,是指两个字串之间,通过替换、插入、删除等操作将字符串str1转换成str2所需要操作的最少字符数量。

php levenshtein()函数 示例

<?php
$data = "hello";
$res = "world";
echo levenshtein($data,$res);
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

输出:

4


<?php
$str1 = "Learning PHP";
$str2 = "is a good choise";
echo levenshtein($str1,$str2);
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

输出:

14

热门推荐