gpt4 book ai didi

PHP Levenshtein 查询结果

转载 作者:行者123 更新时间:2023-11-29 13:59:18 25 4
gpt4 key购买 nike

我想对 mysql 查询结果执行编辑。

查询如下所示:

$query_GID = "select `ID`,`game` from `gkn_catalog`";
$result_GID = $dbc->query($query_GID);
$row_GID = mysqli_fetch_array($result_GID,MYSQLI_ASSOC);

在这里,我准备了编辑操作的所有内容:

$shortest = -1;
$input = $game_title;

这只是手册中的编辑操作:

   foreach ($row_GID as $row) {
$word = $row['game'];

// calculate the distance between the input word,
// and the current word
$lev = levenshtein($input, $word);

// check for an exact match
if ($lev == 0) {
// closest word is this one (exact match)
$closest = $word;
$shortest = 0;

// break out of the loop; we've found an exact match
break;
}
// if this distance is less than the next found shortest
// distance, OR if a next shortest word has not yet been found
if ($lev <= $shortest || $shortest < 0) {
// set the closest match, and shortest distance
$closest = $word;
$shortest = $lev;
}
}
echo "Input word: $input\n";
if ($shortest == 0) {
echo "Exact match found: $closest\n";
} else {
echo "Did you mean: $closest?\n";
}

感谢 Jaitsu,我摆脱了错误/警告消息,但是 levenshtein 现在抛出了意外的结果:

无论输入是什么,它都不会找到匹配的结果,并且最接近的匹配始终是 = H

示例:

Input word: Battlefield 3 Back to Karkand Did you mean: H?
Input word: Starcraft 2 Wings of Liberty Did you mean: H?

说实话,我不知道现在发生了什么......

最佳答案

您从数据库中获取游戏(单词)的逻辑是正确的,但您需要删除...

$words = $row_GID['游戏'];

并将 $row_GID 变量传递到循环中。

然后在你的foreach循环中...

foreach ($row_GID as $row) {
$word = $row['game'];
//proceed as normal
}

关于PHP Levenshtein 查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15339012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com