- array_push: documentation ( source)
- var_dump: documentation ( source)
- array_chunk: documentation ( source)
- print_r: documentation ( source)
<?php
/* Just compose the HTML sample */
$html='<html><head></head><body>';
$html.='<table class="grilla"><tbody><tr class="textEncabezadoGrilla" bgcolor="#C0DAF1" align="center">
<th>Juzgado Policía Local</th>
<th>Rol Causa</th>
</tr>
<tr>
<td class="textgrid2">2 JPL PROVIDENCIA</td>
<td class="textgrid2">018092 - 2010</td>
</tr>
<tr>
<td class="textgrid1">OVALLE JPL</td>
<td class="textgrid1">13115 - 2010</td>
</tr>
</tbody></table>
<table class="grilla"><tbody><tr class="textEncabezadoGrilla" bgcolor="#C0DAF1" align="center">
<th>Juzgado Policía Local</th>
<th>Rol Causa</th>
</tr>
<tr>
<td class="textgrid2">2 JPL PROVIDENCIA</td>
<td class="textgrid2">018092 - 2010</td>
</tr>
<tr>
<td class="textgrid1">OVALLE JPL</td>
<td class="textgrid1">13116 - 2011</td>
</tr>
</tbody></table>';
$html.="</body></html>";
$doc=new DOMDocument();
$doc->loadHTML($html);
$xpath=new DOMXPath($doc);
$tds = array();
var_dump($xpath->query('//table[@class="grilla"]/tbody/tr/td/text()'));
foreach($xpath->query('//table[@class="grilla"]') as $key => $td)
{
array_push($tds, $td);
}
print_r($tds);
$ee = array_chunk($tds, 2);