<?php $user_string = "hallo worl, I wnt to ind a resturan in manhatn"; $subj = explode(" ", $user_string); $str = ["hello", "world", "I", "want", "to", "a", "in" , "find", "eat", "restaurant", "pizza", "Manhattan"]; $minStr = ""; $minDis = PHP_INT_MAX; foreach ($str as $curStr) { Foreach($subj as $word){ $dis = levenshtein($word, $curStr); $dist[$word][$dis][] = $curStr; } } foreach($dist as $key => $word){ echo "the closest word to " . $key . " is " . implode(" and ", $word[min(array_keys($word))]) . "\n"; $sentence[] = implode(" and ", $word[min(array_keys($word))]); } Echo "\n\nUser probably meant: '" .implode(" ", $sentence) . "'";
You have javascript disabled. You will not be able to edit any code.