即時使用下面的代碼來搜索相似的文本。但由於某種原因,無論我搜索什麼,它只會返回相同的值。有人可以看到問題可能是什麼?類似文本搜索
$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>';
我收回...工作正常.. –
沒有硬的感覺=) –