gpt4 book ai didi

php - 使用 MySQL LIKE 语句查找相关文章

转载 作者:行者123 更新时间:2023-11-29 07:15:46 26 4
gpt4 key购买 nike

我正在尝试获取相关文章的列表。示例

$title = $fetch_content[article_name]; // example out put "Hello World, Ask A Question"
$rel_title = "Select * from tbl_content WHERE status='t' and article_name like '%$title' order by id desc limit 5";

如何将“Hello World, Ask A Question”拆分为单个关键字。

最佳答案

您可以使用 split在 PHP 中将标题分解为每个单词的函数:

$title_words = split($title);

$rel_title = 'select * from tbl_content where status = \'t\' and (1=0';

foreach($title as $word)
{
$word = str_replace(',', '', $word);
$word = mysql_real_escape_string($word);
$rel_title .= ' or article_title like \'%' . $word . '%\'';
}

$rel_title .= ')';

echo $rel_title;

我还使用了 str_replace删除问题中的逗号。显然,如果您有其他角色,您可以将其应用到其他角色。

关于php - 使用 MySQL LIKE 语句查找相关文章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1265668/

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