3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on Z6FrR
Output for 5.6.38 - 7.3.0rc3
Warning: DOMDocument::loadHTML(): Opening and ending tag mismatch: tr and table in Entity, line: 7 in /in/3pPYb on line 22 Array ( [0] => Array ( ) [1] => Array ( ) )