缺点
1.只适合英文单词
2.词库需要组合
1.只适合英文单词
2.词库需要组合
<?php
$dictionary = array(
"php", "javascript", "css"
);
$word = "jav scphp";
$best_match = $dictionary[0];
$match_value = levenshtein($dictionary[0], $word);
foreach($dictionary as $w) {
$value = levenshtein($word, $w);
if( $value < $match_value ) {
$best_match = $w;
$match_value = $value;
}
}
// input jav scphp
// output Did you mean the 'javascript' category? - 4
echo "Did you mean the '$best_match' category? - $match_value";
本文介绍了一种基于Levenshtein距离算法实现拼写纠正的方法,并通过PHP代码实例展示了如何从给定词库中找到与输入字符串最接近的匹配词汇。
531

被折叠的 条评论
为什么被折叠?



