假设我检查是否
$strig = "how can i do this";
在我的数据库中已经存在所有单词顺序选项?比如:“我怎么能做到这一点”或“我能做到这一点”……
我的数据库如下所示:
id string
1 how can i do this
2 hello how are you
3 how i can do this world
4 another title
etc etc
谢谢
发布于 2012-04-25 15:23:33
你可以问你正在搜索的字符串是否包含:"how" and "can" and "I" and "do" and "this"
,如下所示:(我不知道mysql中的语法,但请看概念)
if(string.contain("how")&&
string.contain("can")&&
string.contain("I")&&
string.contain("do")&&
string.contain("this"))
{
//you find the string
}
发布于 2012-04-25 15:30:49
应该是mysql中的通配符调用
select * From tablename Where columnname LIKE '%how%'
发布于 2012-04-25 15:49:22
如果您使用的是mysql,请尝试以下命令。
select * from tablename where columnname Like '%how%' AND columnname LIKE '%can%' AND columnname LIKE '%I'% AND columnname LIKE '%DO'% AND columnname LIKE '%This'%;
在这里,如果您在$string
中有动态值,那么首先将其转换为一个数组,按space.then拆分,创建一个可从数组中获取$condition
,并将其附加到select * from tablename
where中,然后运行查询。
谢谢
https://stackoverflow.com/questions/10311020
复制相似问题