与levenshtein一起回归多场比赛

时间:2014-01-02 15:52:56

标签: php levenshtein-distance

如何在PHP中使用levenshtein返回多个类似的匹配?例如,如果我有这个代码:

$input = "Hello what is your name. My namer is Jack.";
$output = "nam";
echo levenshtein($input, $output);

它不仅必须输出name,还必须输出name, namer

我该怎么做?

1 个答案:

答案 0 :(得分:1)

类似的东西:

$input = "Hello what is your name. My namer is Jack.";
$output = "nam";
$threshold = 3;
foreach(str_word_count($input,1) as $word) {
    if (levenshtein($word, $output) < $threshold) {
        echo $word, PHP_EOL;
    }
}