preg_match
成都创新互联公司长期为上1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为永定企业提供专业的网站制作、成都网站制作,永定网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。
(PHP 4, PHP 5)
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.
Report a bug
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.
/*** $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(索引)
用法:
select 字段1,字段2,字段3, MATCH(要匹配的字段名) AGAINST('keyword') as score from table having score0
命中的每一行都会有个分数,分数越大表示结果越接近keyword,分数越低的就是越模糊的结果
模糊匹配:like %关键词%
完全匹配:select 语句 直接等于关键词
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款