这里有讨论贴:
//两个字符串相互比对
$str = "好喝的饮料";
$store = "饮料|咖啡|冷饮|";
$arrData= explode('|',$store);
$sumData= count($arrData);
for($i=0;$i<$sumData;$i++)
{
$back1 = strchr($arrData[$i],$str );
$back2 = strchr($str ,$arrData[$i]);
//任何一个在另外一个存在,就记录
if($back1 != '' || $back2 != '')
{
$id = "ok";
break;
}
}
echo $id;
实例:
//进行所有关键词查找一对一对想到匹配
$key_list = $publish->where("status=0 and keywords<>''")->order("ord asc,id desc")->field("id,keywords")->select();
if ($key_list){
foreach ($key_list as $m=>$n){
$n['keywords'] = str_replace(",",",",$n['keywords']);
if (substr_count($n['keywords'],',')){
$new_array = explode(",", $n['keywords']);
$array_1 = array();
foreach ($new_array as $j=>$l){
unset($new_array[$j]);
$array_1['id'] = $n['id'];
$array_1['keywords'] = $l;
$key_list[] = $array_1;
}
unset($key_list[$m]);
}
}
$c = count($key_list);
for($i=0;$i<$c;$i++){
$back1 = strchr($key_list[$i]['keywords'],$content);
$back2 = strchr($content, $key_list[$i]['keywords']);
if ($back1 != "" || $back2 != ""){
$id = $key_list[$i]['id'];
break;
}
}
if ($id){
$find = $publish->where("id={$id}")->find();
}
}