PHP How remove element from html dom? -


this question has answer here:

we have index.php code:

<div class="test"> text text text text</div> <div class="test2"> text text text text</div> <div class="test3"> text text text text</div> <div class="test4"> text text text text</div> 

in file test.php use code:

ob_start(); // start output buffer include 'index.php'; $template = ob_get_contents(); // contents of buffer ob_end_clean(); return $template; 

tell me please how remove div class test2 , content in him html in $template?

p.s.: want remove div class test2 regardless of attributes inside div tag.

okay, have html structure in variable. can remove preg_replace.

$template = preg_replace('/<div.*?class="test2".*?>.*?</div>/','', $template); 

another way use dom parser.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -