3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<html> <body> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> <TR> <TD BGCOLOR=000000> <table> <tr> <td>Name</td> <td>Date</td> </tr> <tr> <td>Chad</td> <td>10/23/1996</td> </tr> <tr> <td>Rebecca</td> <td>05/03/2001</td> </table> </body> </html>'; $dom = new DOMDocument(); $dom->loadHTML($html); // Grab first table from dom and store its rows and columns by tag name. $rows = $dom->getElementsByTagName('table')->item(1)->getElementsByTagName('tr'); $headers = $rows->item(0); $resultArray = []; $keys = []; foreach($headers as $header) { $keys[] = strtolower($cell->nodeValue); } foreach($rows as $row) { $item = []; foreach($keys as $i=>$key) { $cells = $row->getElementsByTagName('td'); $item[$key] = $cells->item($i)->nodeValue; } $resultArray[] = $item; } print_r($resultArray);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $cell in /in/Z6FrR on line 33 Warning: Attempt to read property "nodeValue" on null in /in/Z6FrR on line 33 Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /in/Z6FrR on line 33 Array ( [0] => Array ( [] => Name ) [1] => Array ( [] => Chad ) [2] => Array ( [] => Rebecca ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.68 ms | 402 KiB | 8 Q