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);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: DOMDocument::loadHTML(): Opening and ending tag mismatch: tr and table in Entity, line: 7 in /in/3pPYb on line 22 Warning: Undefined variable $cell in /in/3pPYb on line 32 Warning: Attempt to read property "nodeValue" on null in /in/3pPYb on line 32 Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /in/3pPYb on line 32 Array ( [0] => Array ( [] => Chad ) [1] => Array ( [] => Rebecca ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: DOMDocument::loadHTML(): Opening and ending tag mismatch: tr and table in Entity, line: 7 in /in/3pPYb on line 22 Warning: Undefined variable $cell in /in/3pPYb on line 32 Warning: Attempt to read property "nodeValue" on null in /in/3pPYb on line 32 Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /in/3pPYb on line 32 Array ( [0] => Array ( [] => Chad ) [1] => Array ( [] => Rebecca ) )
Output for 5.6.38, 7.1.0 - 7.1.23, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
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 ( ) )

preferences:
156.39 ms | 403 KiB | 173 Q