PHP How remove element from html dom? -
this question has answer here:
- how delete element domdocument? 3 answers
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
Post a Comment