如何在PHP中使用levenshtein返回多个类似的匹配?例如,如果我有这个代码:
$input = "Hello what is your name. My namer is Jack.";
$output = "nam";
echo levenshtein($input, $output);
它不仅必须输出name
,还必须输出name, namer
。
我该怎么做?
答案 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;
}
}