clean html a string by element id using php

Posted by user327140 on Stack Overflow See other posts from Stack Overflow or by user327140
Published on 2010-04-27T18:37:18Z Indexed on 2010/04/28 9:03 UTC
Read the original article Hit count: 344

Filed under:
|
|
|

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,

© Stack Overflow or respective owner

Related posts about php

Related posts about html