preg_match
preg_match — Perform a regular expression match
Report a bug
Description
int preg_match ( string $pattern , string $subject [, array $matches [, int $flags = 0 [, int $offset = 0 ]]] )
Searches subject for a match to the regular expression given in pattern.
Parameters
pattern
The pattern to search for, as a string.
subject
The input string.
matches
If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
flags
flags can be the following flag:
PREG_OFFSET_CAPTURE
If this flag is passed, for every occurring match the appendant string offset will also be returned. Note that this changes the value of matches into an array where every element is an array consisting of the matched string at offset 0 and its string offset into subject at offset 1.
模糊匹配:like %关键词%
完全匹配:select 语句 直接等于关键词
/*** $array---需要被的数组* $str --- 要查询的字符串* $return -- 返回匹配该字符串的数组的下标集合.*/public function search($array,$str){ foreach($all as $key=$val){ $retrun = array(); // 如果$key中含有$str字符串,那么添加到数组$return中 if(stripos($key,$str) != false || stripos($key,$str) == '0') { array_push($retrun ,$key); }}return $return;}
mysql支持自然语言的全文搜索
对于字段的要求:
只能是CHAR, VARCHAR, 或 TEXT 类型的字段
表类型是MyISAM
在表建好,并导入数据后,建立一个fulltext index(索引)
用法:
命中的每一行都会有个分数,分数越大表示结果越接近keyword,分数越低的就是越模糊的结果
以上就是土嘎嘎小编为大家整理的php数据模糊匹配算法相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!