开发者

use regular expression in php

开发者 https://www.devze.com 2023-01-06 12:20 出处:网络
..(content)............. <A HREF=\"http://test.com/content\" >test link </A> ...(continue 开发者_如何学Pythoncontent)...
..(content).............
<A HREF="http://test.com/content" >test link </A>
...(continue 开发者_如何学Pythoncontent)...

I want to delete link with content. And also text between link.


I wouldn't use regex here at all - rather DOMDocument::loadHTML, then DOMDocument::getElementsByTagName and DOMNode::removeChild; finally DOMDocument::saveHTML


While regular expressions can be used to do this, they will be prone to problems. A more robust solution is using the DOM extension or another HTML parser to remove the a element in question. Or all a elements, for that matter. If you really want to do this with a regular expression, the following should work:

preg_replace('/<A (.*?)>(.*?)</A>/i', '', $data);
0

精彩评论

暂无评论...
验证码 换一张
取 消