Reputation: 1452
I want to change this:
<div>
<div>
<div id="myList">
<table><tr><td></td></tr></table>
</div>
</div>
</div>
Into this:
<table><tr><td></td></tr></table>
What would the preg_replace() be? I have tried the following but to no avail:
$result = preg_replace('#<div(.*?)(?! id="myList")>(.*?)</div>#is', '', $result);
Upvotes: 1
Views: 493
Reputation: 254
@Reado try this
$s='<div>
<div>
<div id="myList">
<table><tr><td></td></tr></table>
</div>
</div>
</div>';
$replace=str_replace(array('<div>', '<div id="myList">','</div>'),"",$s);
Upvotes: 1
Reputation: 24276
You can use strip_tags
$string = '<div>
<div>
<div id="myList">
<table><tr><td></td></tr></table>
</div>
</div>
</div>';
echo strip_tags($string, '<table><tr><td>');
Upvotes: 4