Question

How can I return multiple similar matches with levenshtein in PHP? For example if I have this code:

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

It must not only output name, but name, namer.

How can I do that?

Était-ce utile?

La solution

Something like:

$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;
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top