- implode: documentation ( source)
<?php
/* Just compose the HTML sample */
$html='<html><head></head><body><table id="myTable">';
for($i=0;$i<100;$i++)
{
$html.="<tr><td>info{$i}.1</td><td>info{$i}.2</td><td>info{$i}.3</td></tr>";
}
$html.="</table></body></html>";
$doc=new DOMDocument();
$doc->loadHTML($html);
$xpath=new DOMXPath($doc);
echo "<table>\n";
/* 10 is the row count */
for($i=0;$i<10;$i++)
{
echo "<tr>\n";
/* 10 is the column count */
foreach($xpath->query('//table[@id="myTable"]/tr[position()>'.($i*10).' and position()<'.(($i+1)*10+1).']') as $tr)
{
echo "\t<td>";// "\t" to make it look nice
$tds=array();
foreach($tr->childNodes as $td)
{
if($td->nodeName!="td") continue;
$tds[]=$td->firstChild->nodeValue;
}
echo implode("<br />",$tds);
echo "</td>\n";
}
echo "</tr>\n";
}
echo "</table>";