我有一个文本“a href
”和“[link]
”链接。我想使preg_split这段文字,并有数组,其中的[I]我能找到的链接PHP - 正则表达式来拆分URL
例子:
My text <a href="www.example.com">text</a> this continues [link=http://www.second.com]link[/link]
=>
[0] My text
[1] <a href="www.example.com">text</a>
[2] this continues
[3] [link=http://www.second.com]link[/link]
我应该怎样写我的正则表达式?
不要PA用正则表达式rse HTML。使用[PHP附带的DOM模块](http://php.net/manual/en/book.dom.php)。正则表达式并不总是使用的工具,即使问题涉及到文本。 –