【发布时间】:2019-09-27 05:53:55
【问题描述】:
我的文本格式为:
Txx8xxTT<br><br><br>https://wwww.xxx.com<br><br />
<br />cxyc[link=http://www.example.com]link[/odkaz]
xxx<a href="http://www.example2.com">link2</a>
我想使用 preg_match_all 解析它,在结果数组中,所有独立链接都位于单独的索引处。在示例情况下,我想要这样的东西:
[0] => Txx8xxTT<br><br><br>
[1] => https://wwww.xxx.com
[2] => <br><br />
<br />cxyc[link=http://www.example.com]link[/odkaz]
xxx<a href="http://www.example2.com">link2</a>
(数组的格式可以不同,我不关心索引,但我希望单独的链接在它自己的索引处)
我尝试将preg_match_all 与(.[^ \<\[]*) 一起使用。它几乎可以工作,但我在索引 [3] 处得到的结果为 <br>https://wwww.xxx.com,我不想要 <br> 前缀。
[0] => Txx8xxTT
[1] => <br>
[2] => <br>
[3] => <br>https://wwww.xxx.com
[4] => <br>
[5] => <br
[6] => />
[7] => <br
[8] => />cxyc
[9] => [link="http://www.example.com"]link
[10] => [/odkaz]xxx
[11] => <a
[12] => href="http://www.example2.com">link2
[13] => </a>
【问题讨论】:
-
不要使用正则表达式。它确实不适合这个任务。 stackoverflow.com/questions/1732348/…
标签: php regex preg-match-all