php关键字搜索
或者叫,分词检索数据库
$res
=
mysql_query("select
*
from
peter
where
id
like
'%中草药%'
and
'%6%'");
//这样写是报错的;
$res
=
mysql_query("select
*
from
peter
where
id
like
'%中草药%'
or
'%6%'");
//而这样写是正确的;奇怪~
$res
=
mysql_query("select
*
from
peter
where
id
like
'%中草药%'
and
id
like
'%6%'");
//这样写是正确的;
$res
=
mysql_query("select
*
from
peter
where
id
like
'%中草药%'
or
id
like
'%6%'");
//这样写都是正确的;
以上就是小编为大家带来的php
mysql
like
实现多关键词搜索的方法全部内容了,希望大家多多支持脚本之家~
㈡ php正则表达式按关键字搜索文件
$list=scandir('./help');$key=$_GET['k'];$dir=$_GET['dir'];//文件目录,可以指定function key_search($dir){global $key;</p><p>$list=scandir($dir);</p><p>if($list){</p><p>foreach($list as $v){</p><p>if($v!='.' or $v!='..'){</p><p>$f=$dir.$v;</p><p>if(<strong>is_dir</strong> ($f)){scandir($f);}else{if(!stristr($v,$key)){echo $v;}}}}}else{echo $dir.'文件夹不存在';} 注:1,程序请自行测试2,子目录可能需要检查最后字符是否为/,如果不是,则添加。3,你的说明很有问题,一会儿要找,一会又说不包含。 }
㈢ PHP怎么实现检索文件内容中存在关键字的文件
先遍历目录文件,把文件名保存到数据,然后使用函数检索文件名是否包含关键词即可。
㈣ PHP 数组 怎么实现关键词查找
这个关键词是包含在数组中的key中还是value中?
如果是包含在key中的话,可以这么写
foreach($arrayas$k=>$v){
if(strstr($k,$keyword,true)){
return$k;
}
}
如果关键词包含在value中的话,就这么写
foreach($arrayas$k=>$v){
if(strstr($v,$keyword,true)){
return$v;
}
}
㈤ PHP中怎么实现关键字搜索
PHP要实现关键字查搜索,需要用到like关键字来组合查询条件
like具体实现方法如下:
例一:
1$userForm=M('user');
1$where['name']=array('like','phpernote%');
2$userForm->where($where)->select();
这里的like查询即为:name like 'phpernote%'
例二:
1$where['name']=array('like',array('%phpernote%','%.com'),'OR');
这里的like查询即为:name like '%phpernote%' or name like '%.com'
例三:
1$where['name']=array(array('like','%a%'),array('like','%b%'),array('like','%c%'),'phpernote','or');
这里的like查询即为:(`name` LIKE '%a%') OR (`name` LIKE '%b%') OR (`name` LIKE '%c%') OR (`name` = 'phpernote')
例四:
1$where['_string']='(namelike"%phpernote%")OR(titlelike"%phpernote")'
这里的like查询即为:name like '%phpernote%' or title like '%phpernote'