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> <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);

preferences:
30.91 ms | 402 KiB | 5 Q