clean html a string by element id using php -
as can see subject looking tool cleaning html string in php using html id property, example:
according following php string wish clean html erasing 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 tried tool htmlpurifier.org , can't desirable result. thing achieved removing elements tag; erasing id; erasing class.
is there simple way achieve using purifier or other?
thanks in advance,
as general solution manipulating html data, recommend :
- loading dom document :
domdocument::loadhtml - manipulating dom
- for example, here, you'll use
domdocument::getelementbyid - and
domnode::removechild
- for example, here, you'll use
- get new html string,
domdocument::savehtml
note : it'll add tags arround html, domdocument::savehtml generates html corresponds full html document :-(
a couple of str_replace remove might ok, suppose... it's not hardest part of work, , should work fine.
Comments
Post a Comment