Home > Backend Development > PHP Tutorial > PHP如何快速找出字符串中匹配的字符(不能用正则)

PHP如何快速找出字符串中匹配的字符(不能用正则)

WBOY
Release: 2016-06-13 12:47:37
Original
978 people have browsed it

PHP怎么快速找出字符串中匹配的字符(不能用正则)

<br />
$tags =  "中国,百度中国,人中国,漫画交流"; //固定数据格式<br />
<br />
$tags_array = explode(',',$tag);<br />
<br />
$match_result = array(); //匹配的结果<br />
<br />
foreach($tags_array as $v){<br />
      if(strpos($v,'中国') === false){<br />
          continue; <br />
      }<br />
      $match_result[] = $v;<br />
}<br />
<br />
//输出结果<br />
Array<br />
(<br />
    [0] => 中国<br />
     [1] => 百度中国<br />
     [2] => 人中国<br />
)<br />
<br />
Copy after login


当然也可以用正则去匹配,我是想知道有没有更快的方法,谢谢大家!

PHP 字符串
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template