3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <html> <head> </head> <body> <table> <tbody> <tr> <td>header1</td> <td>header2</td> <td>header3</td> </tr> <tr> <td>content1</td> <td>content2</td> <td>content3</td> </tr> <tr> <td>test1</td> <td>test2</td> <td>test3</td> </tr> </tbody> </table> </body> </html> HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $result = []; foreach ($dom->getElementsByTagName('tr') as $i => $row) { foreach ($row->getElementsByTagName('td') as $c => $cell) { $result[$c][$i] = $cell->nodeValue; } } var_export($result);

preferences:
70.15 ms | 1153 KiB | 5 Q