To remove elements and content, there are mainly two methods:
remove()
- Removes the selected element (and its child elements)
clear()
- Removes the child elements from the selected element
$doc->Q([selector])->remove();
$doc->Q([selector])->clear();
<div id="div1"
style="height:100px;width:300px;
border:1px solid black;background-color:yellow;">
This is some text in the div.
<p>This is a paragraph in the div.</p>
<p>This is another paragraph in the div.</p>
</div>
<div id="div2"
style="height:100px;width:300px;
border:1px solid black;background-color:yellow;">
This is some text in the div.
<p>This is a paragraph in the div.</p>
<p>This is another paragraph in the div.</p>
</div>
Php
<?php
include "../src/webparser.php";
$doc = new WebParser();
$doc->loadHTML($html);
$doc->Q("#div1")->remove();
$doc->Q("#div2")->clear();
$doc->output();
Output
<div id="div2" style="height:100px;width:300px;border:1px solid black;
background-color:yellow;">
</div>
Click here to go to example test.