Frage

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?

War es hilfreich?

Lösung

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;
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top