3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<EOT <html> Some html <a class="title" href="showthread.php?t=XXXXX" id="thread_title_5">DATADATA</a> More html <a class="title" href="showthread.php?t=987654" id="thread_title_1234">inner text</a> </html> EOT; $dom = new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); foreach ($xpath->query('//a[starts-with(@href, "showthread.php")]') as $node) { parse_str(parse_url($node->getAttribute('href'), PHP_URL_QUERY), $queryString); printf( "t: %s\ntitle: %s\ninnerHTML: %s\n---\n", $queryString['t'] ?? 'no query string', filter_var($node->getAttribute('id'), FILTER_SANITIZE_NUMBER_INT), $node->nodeValue ); }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
t: XXXXX title: 5 innerHTML: DATADATA --- t: 987654 title: 1234 innerHTML: inner text ---

preferences:
102.91 ms | 1507 KiB | 4 Q