3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = ' <table id="myTable"> <tbody> <tr> <td>08/20/18</td> <td> <a href="https://example.com/1a">Text 1 A</a> </td> <td> <a href="https://example.com/1b">Test 1 B</a> </td> </tr> <tr> <td>08/21/18</td> <td> <a href="https://example.com/2a">Text 2 A</a> </td> <td> <a href="https://example.com/2b">Test 2 B</a> </td> </tr> </tbody> </table> '; // setup DOMDocument $doc = new DOMDocument(); $doc->loadHTML('<?xml encoding="utf-8" ?>' . $html); $xpath = new DOMXPath($doc); // target table using xpath $results = $xpath->query("//*[@id='myTable']"); if ($results->length > 0) { // Results object print_r($results->item(0)); // Results nodeValue print_r($results->item(0)->nodeValue); }

preferences:
29.51 ms | 404 KiB | 5 Q