clean html a string by element id using php
- by user327140
Hi, as you can see by the subject am looking for a tool for cleaning up a HTML string in php using a HTML id property, example:
According to the following PHP string I wish to clean the HTML erasing the black11
$test = '
<div id="block1">
<div id="block11">Hello1 <span>more html here...</span></div>
<div id="block12">Hello2 <span>more html here...</span></div>
</div>
<div id="block2"></div>
';
Will became
$test = '
<div id="block1">
<div id="block12">Hello2 <span>more html here...</span></div>
</div>
<div id="block2"></div>
';
I already tried the tool from htmlpurifier.org and can't get the desirable result. Only thing I achieved was removing elements by tag; erasing id; erasing class.
Is there any simple way to achieve this using purifier or other?
Thanks in advance,