tarique
tarique

Reputation: 1

use regular expression in php

..(content).............
<A HREF="http://test.com/content" >test link </A>
...(continue content)...

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

Upvotes: 0

Views: 98

Answers (2)

You
You

Reputation: 23774

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);

Upvotes: 0

Piskvor left the building
Piskvor left the building

Reputation: 92752

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

Upvotes: 3

Related Questions