<?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 ); }
You have javascript disabled. You will not be able to edit any code.