i’m stuck with the subj question.
this is the sample code:
include('./simple_html_dom.php');
$html = str_get_html("
<cols>
<br>
<col>
content1
<br>
content1
</col>
<br>
<col>
<br>
content2
<br>
content2
</col>
<br>
</cols>");
foreach($html->find('cols br') as $br) {
echo $br->outertext;
}
this gives me all the <br> tags inside the <cols> tag, but i need the <br>‘s only on the top level.
$html->find('cols > br') doesnt work also(
UPDATE
resolve this :
foreach($html->find('cols') as $cols_tag_content) {
for($node = 0; $node < count($cols_tag_content->children()); $node++) {
if($cols_tag_content->children($node)->tag == "br") {
//doing whatever you want with br. i just remove it
$cols_tag_content->children($node)->outertext = "";
}
}
}
this works with <br> and <br />
1 Answer