【发布时间】:2011-03-04 13:51:32
【问题描述】:
我被主题问题困住了。
这是示例代码:
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) {
回声 $br-> 外文;
}
这给了我<cols> 标签内的所有<br> 标签,但我只需要顶层的<br>。$html->find('cols > br') 也不起作用(
更新
解决这个问题:
这适用于
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 = "";
}
}
}
<br> 和<br />
【问题讨论】: