im using the following code to search for similar text. But for some reason it only returns the same value no matter what i search. can someone see what the issue might be?
$result = mysql_query("SELECT keyword FROM search");
$storeArray = Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$storeArray[] = $row['keyword'];
}
foreach ($storeArray as $key){
//echo "'".$key."'";
}
$my_word = $_POST['value'];
$all_words = array(
"'".$key."'"
);
$bestMatch = array('word' => $my_word, 'match' => 2);
foreach($all_words as $word) {
similar_text($word, $my_word, $percent);
if($percent > $bestMatch['match']) $bestMatch = array('word' => $word, 'match' => $percent);
}
if($bestMatch['match'] < 100) echo 'Did you mean: <strong>' . $bestMatch['word'] . '</strong>';
I edited it a little, tell me if this is what you want.
EDIT: don’t forget that
similar_textwas shown to give good results only for words who already have a big similarity (in terms of length mainly), I think it’s an 80% resemblance (combining both character counts and lengths). Not 100% sure though…