I'm using this parser:
http://simplehtmldom.sourceforge.net/
I want to get all of the cells that are direct children of the parent table, not all of the cells within the table. This is because I could have nested tables within cells.
Consider the following example:
Code:
<table border="1" id="mytable">
<tr>
<td bgcolor="#e8e8e8">1</td>
<td bgcolor="#e8e8e8">2</td>
</tr>
<tr>
<td bgcolor="#e8e8e8">3</td>
<td bgcolor="#e8e8e8">4</td>
</tr>
<tr>
<td bgcolor="#e8e8e8">
<table border="1">
<tr>
<td bgcolor="#fff">11</td>
<td bgcolor="#fff">12</td>
</tr>
<tr>
<td bgcolor="#fff">13</td>
<td bgcolor="#fff">14</td>
</tr>
<tr>
<td bgcolor="#fff">15</td>
<td bgcolor="#fff">16</td>
</tr>
</table>
</td>
<td bgcolor="#e8e8e8">6</td>
</tr>
</table>
Right now, if I execute this code:
PHP Code:
$html->find('#mytable')->find('td');
foreach($t as $k) {
echo $k->innertext;
}
...it will retrieve: 1, 2, 3, 4, 11, 12, 13, 14, 15, 16, 6.
I want it to print ONLY the content of the direct children cells (1, 2, 3, 4, <table>...</table>, 6).
I tried writing a recursive function to get the nested level of the table in the DOM tree, but that didn't work and made the code convoluted. Any suggestions?
Bookmarks