gpt4 book ai didi

php - 如何通过许多类似的检查在 SQL 语句中获取匹配的字符串部分

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:18 25 4
gpt4 key购买 nike

有没有可能,在有很多like语句的sql语句中得到匹配的字符串部分。

SELECT fieldname
FROM table
WHERE content LIKE '%$val_1%'
OR content LIKE '%$val_2%'
OR content LIKE '%$val_3%'
.
.
.
OR content LIKE '%$val_n%'

即我需要获取所有匹配内容的值($val_1, or(and) $val_2 ...)

示例

如果我的内容如下

content = 'this is my testing text'

我有以下值,用于检查类似的语句

$val_1 = 'thi';
$val_2 = 'esting';
$val_3 = 'other value, which not in my content';

我需要获取匹配的部分,即 “thi”“esting”,因为它们在我的内容中是匹配的。

最佳答案

既然你说你是用 PHP 做的,那么在你得到你的行后只需使用 PHP 找出匹配的位:

if (stripos($row['content'], $val_1) !== false) this bit matched!
if (stripos($row['content'], $val_2) !== false) this bit matched!
if (stripos($row['content'], $val_3) !== false) this bit matched!

关于php - 如何通过许多类似的检查在 SQL 语句中获取匹配的字符串部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9070491/

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