PHP学习_PHP技术_PHP网站建设_PHP程序员专注于PHP技术研究及学习

Adophper » 数据库 » PHP+MYSQL数据库关键词模糊匹配查找

PHP+MYSQL数据库关键词模糊匹配查找

此文被围观2514日期: 2014-01-17 分类 : 数据库  标签:  ·····
这里有讨论贴:
//两个字符串相互比对 $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(); } }

本站使用ThinkPHP框架开发读图网主题,目前托管在阿里云,图片由读图网提供. 蜀ICP备12031064号

Copyright © 2011-2017adophper.com All Rights Reserved.