First, I know about Simple HTML Dom parser and PHP's built-in solution, which none of them are doing exactly that kind of job I'm asking for (not to my knowledge).
I'm looking for PHP's PCRE that will find the element and the belonging content inside DOM, delete it and forgive if markup contains any extra whitespace.
Here is code:
<div id="maindiv">
<div class="unusefuldiv1">Unuseful content</div>
<div id="unusefuldiv2">Unuseful content2</div>
<!-- ... some content I'm after for -->
</div>
I'm desperate about regular expression pattern that will delete both .uunusefuldiv1 and #unusefuldiv2 (markup together with content) and be (if possible) enough flexible to do the job if,
for example <div class="unusefuldiv1">
is slightly mistyped with extra empty space: <div class="unusefuldiv1" >
.
That might be something similar to
preg_replace('/<div\b[^>]*>(.*?)<\/div>/is', '', $dom_content);
except that this pattern will delete all div's, be them with of some classes, id's or without.
Does anyone have solution?