preg_match_all匹配重复内容的时候怎么打印出所有被重复匹配的内容

WBOY
Release: 2016-06-13 12:26:22
Original
1124 people have browsed it

preg_match_all匹配重复内容的时候如何打印出所有被重复匹配的内容
先贴代码:
$str = '{if aa eq bb or cc eq dd or ee eq ff}';
$patten = '/\{(.*?)eq(.*?)(or(.*?))*\}/';
preg_match_all($patten,$str,$patten_all);
var_dump($patten_all);
我看了下patten_all这个参数我希望保存了所有匹配到的or和之后的内容,但事实上只保存了最后一个匹配的内容,即使缓存preg_match来匹配也没法保存,贴下刚这段代码的运行结果:

如果我现在想要patten_all这个参数能保存所有匹配到所有的or xxx并且保存到数组中话,正则应该怎么改或者该用什么函数呢?
------解决思路----------------------
这样可能符合你的要求

$str = '{if aa eq bb or cc eq dd or ee eq ff}';<br />$patten = '/(?:if<br><font color='#FF8000'>------解决思路----------------------</font><br>or)\s+((\S+)\s+eq\s+([^ }]+))/';<br />preg_match_all($patten,$str,$patten_all);<br />var_dump($patten_all);
Copy after login
array(4) {<br />  [0]=><br />  array(3) {<br />    [0]=><br />    string(11) "if aa eq bb"<br />    [1]=><br />    string(11) "or cc eq dd"<br />    [2]=><br />    string(11) "or ee eq ff"<br />  }<br />  [1]=><br />  array(3) {<br />    [0]=><br />    string(8) "aa eq bb"<br />    [1]=><br />    string(8) "cc eq dd"<br />    [2]=><br />    string(8) "ee eq ff"<br />  }<br />  [2]=><br />  array(3) {<br />    [0]=><br />    string(2) "aa"<br />    [1]=><br />    string(2) "cc"<br />    [2]=><br />    string(2) "ee"<br />  }<br />  [3]=><br />  array(3) {<br />    [0]=><br />    string(2) "bb"<br />    [1]=><br />    string(2) "dd"<br />    [2]=><br />    string(2) "ff"<br />  }<br />}<br /><br />
Copy after login

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!