有没有可能,在有很多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!
我是一名优秀的程序员,十分优秀!