php levenshtein() 函数

时间:2016-03-23
php levenshtein() 函数可以方便的返回两个参数之间的levenshtein(编辑距离)。曾经遇到过一个需求,用户在编辑身份证的时候,限制用户只能修改4位数字,使用的就是这个函数。

<?php
    $idcard='230406198506206797';
    $newIdcard='230406198506207798';
    echo levenshtein($idcard,$newIdcard);  //输出 2
?>

在线运行