這確實是一個奇怪的行爲...即使使用>
意味着直接的孩子,不工作!
檢查:
$input = <<<_DATA_
<table id="a">
<thead>
<tr>empty</tr>
</thead>
<tbody>
<tr>
content I want is here
</tr>
</tbody>
</table>
_DATA_;
//Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($input);
foreach($html->find('tbody > tr') as $tr){
// The parent tag name
$parentTag = $tr->parent()->tag;
echo $parentTag . ' => ' . $tr->plaintext;
// Make sure the parent tag is 'tbody'
if($parentTag == 'tbody')
echo ' => OK';
echo '<br>';
}
OUTPUT
thead => empty
tbody => content I want is here => OK
因此,一個workarround將是檢驗如果父等於如上述CHOWN
適當的值