3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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>";
Output for 5.0.0 - 7.1.0
<table> <tr> <td>info0.1<br />info0.2<br />info0.3</td> <td>info1.1<br />info1.2<br />info1.3</td> <td>info2.1<br />info2.2<br />info2.3</td> <td>info3.1<br />info3.2<br />info3.3</td> <td>info4.1<br />info4.2<br />info4.3</td> <td>info5.1<br />info5.2<br />info5.3</td> <td>info6.1<br />info6.2<br />info6.3</td> <td>info7.1<br />info7.2<br />info7.3</td> <td>info8.1<br />info8.2<br />info8.3</td> <td>info9.1<br />info9.2<br />info9.3</td> </tr> <tr> <td>info10.1<br />info10.2<br />info10.3</td> <td>info11.1<br />info11.2<br />info11.3</td> <td>info12.1<br />info12.2<br />info12.3</td> <td>info13.1<br />info13.2<br />info13.3</td> <td>info14.1<br />info14.2<br />info14.3</td> <td>info15.1<br />info15.2<br />info15.3</td> <td>info16.1<br />info16.2<br />info16.3</td> <td>info17.1<br />info17.2<br />info17.3</td> <td>info18.1<br />info18.2<br />info18.3</td> <td>info19.1<br />info19.2<br />info19.3</td> </tr> <tr> <td>info20.1<br />info20.2<br />info20.3</td> <td>info21.1<br />info21.2<br />info21.3</td> <td>info22.1<br />info22.2<br />info22.3</td> <td>info23.1<br />info23.2<br />info23.3</td> <td>info24.1<br />info24.2<br />info24.3</td> <td>info25.1<br />info25.2<br />info25.3</td> <td>info26.1<br />info26.2<br />info26.3</td> <td>info27.1<br />info27.2<br />info27.3</td> <td>info28.1<br />info28.2<br />info28.3</td> <td>info29.1<br />info29.2<br />info29.3</td> </tr> <tr> <td>info30.1<br />info30.2<br />info30.3</td> <td>info31.1<br />info31.2<br />info31.3</td> <td>info32.1<br />info32.2<br />info32.3</td> <td>info33.1<br />info33.2<br />info33.3</td> <td>info34.1<br />info34.2<br />info34.3</td> <td>info35.1<br />info35.2<br />info35.3</td> <td>info36.1<br />info36.2<br />info36.3</td> <td>info37.1<br />info37.2<br />info37.3</td> <td>info38.1<br />info38.2<br />info38.3</td> <td>info39.1<br />info39.2<br />info39.3</td> </tr> <tr> <td>info40.1<br />info40.2<br />info40.3</td> <td>info41.1<br />info41.2<br />info41.3</td> <td>info42.1<br />info42.2<br />info42.3</td> <td>info43.1<br />info43.2<br />info43.3</td> <td>info44.1<br />info44.2<br />info44.3</td> <td>info45.1<br />info45.2<br />info45.3</td> <td>info46.1<br />info46.2<br />info46.3</td> <td>info47.1<br />info47.2<br />info47.3</td> <td>info48.1<br />info48.2<br />info48.3</td> <td>info49.1<br />info49.2<br />info49.3</td> </tr> <tr> <td>info50.1<br />info50.2<br />info50.3</td> <td>info51.1<br />info51.2<br />info51.3</td> <td>info52.1<br />info52.2<br />info52.3</td> <td>info53.1<br />info53.2<br />info53.3</td> <td>info54.1<br />info54.2<br />info54.3</td> <td>info55.1<br />info55.2<br />info55.3</td> <td>info56.1<br />info56.2<br />info56.3</td> <td>info57.1<br />info57.2<br />info57.3</td> <td>info58.1<br />info58.2<br />info58.3</td> <td>info59.1<br />info59.2<br />info59.3</td> </tr> <tr> <td>info60.1<br />info60.2<br />info60.3</td> <td>info61.1<br />info61.2<br />info61.3</td> <td>info62.1<br />info62.2<br />info62.3</td> <td>info63.1<br />info63.2<br />info63.3</td> <td>info64.1<br />info64.2<br />info64.3</td> <td>info65.1<br />info65.2<br />info65.3</td> <td>info66.1<br />info66.2<br />info66.3</td> <td>info67.1<br />info67.2<br />info67.3</td> <td>info68.1<br />info68.2<br />info68.3</td> <td>info69.1<br />info69.2<br />info69.3</td> </tr> <tr> <td>info70.1<br />info70.2<br />info70.3</td> <td>info71.1<br />info71.2<br />info71.3</td> <td>info72.1<br />info72.2<br />info72.3</td> <td>info73.1<br />info73.2<br />info73.3</td> <td>info74.1<br />info74.2<br />info74.3</td> <td>info75.1<br />info75.2<br />info75.3</td> <td>info76.1<br />info76.2<br />info76.3</td> <td>info77.1<br />info77.2<br />info77.3</td> <td>info78.1<br />info78.2<br />info78.3</td> <td>info79.1<br />info79.2<br />info79.3</td> </tr> <tr> <td>info80.1<br />info80.2<br />info80.3</td> <td>info81.1<br />info81.2<br />info81.3</td> <td>info82.1<br />info82.2<br />info82.3</td> <td>info83.1<br />info83.2<br />info83.3</td> <td>info84.1<br />info84.2<br />info84.3</td> <td>info85.1<br />info85.2<br />info85.3</td> <td>info86.1<br />info86.2<br />info86.3</td> <td>info87.1<br />info87.2<br />info87.3</td> <td>info88.1<br />info88.2<br />info88.3</td> <td>info89.1<br />info89.2<br />info89.3</td> </tr> <tr> <td>info90.1<br />info90.2<br />info90.3</td> <td>info91.1<br />info91.2<br />info91.3</td> <td>info92.1<br />info92.2<br />info92.3</td> <td>info93.1<br />info93.2<br />info93.3</td> <td>info94.1<br />info94.2<br />info94.3</td> <td>info95.1<br />info95.2<br />info95.3</td> <td>info96.1<br />info96.2<br />info96.3</td> <td>info97.1<br />info97.2<br />info97.3</td> <td>info98.1<br />info98.2<br />info98.3</td> <td>info99.1<br />info99.2<br />info99.3</td> </tr> </table>
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/lrOLg on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/lrOLg on line 9