preg replace - php - strip same tags as parent tag -


how can strip same tags parent tag using preg_replace ? example have tag called <strip> , want strip child tags <strip> example <strip><strip>avoid tag</strip></strip> want become --> <strip>avoid tag</strip> don't know preg_* thats have:

preg_replace_callback(   '#\<strip\>(.+?)\<\/strip\>#s',   create_function(     '$matches',     'return "<strip>".htmlentities($matches[1])."</strip>";'   ),   $content ); 

this little function apply htmlentities inside <strip> tags , idon't want <strip> tag repeated inside each other

thanks

please dont user regex html dom, take @ domxpath doc here

a shot exemple here :

$doc = new domdocument(); $doc->loadhtmlfile($file); $xpath = new domxpath($doc); $elements = $xpath->query("/html/body/*"); foreach ($elements $element) {     $nodes = $element->childnodes;     foreach ($nodes $node) {       //do stuff here :)        echo $node->nodevalue. "\n";     } } 

if it's xml take @ simplexmlelement here


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -