- file_get_contents: documentation ( source)
- preg_match: documentation ( source)
- print_r: documentation ( source)
- header: documentation ( source)
- libxml_use_internal_errors: documentation ( source)
<?php
header('Content-Type: text/plain; charset=utf-8');
$body = file_get_contents('http://chat.stackoverflow.com/search?q=tag%3Acv-pls%20tag%3Adelv-pls&Room=11&page=1&pagesize=50&sort=newest');
$qids = [];
libxml_use_internal_errors(true);
$doc = new DOMDocument;
$doc->loadHTML($body);
$xpath = new DOMXpath($doc);
$nodes = $xpath->query("//a[contains(@href, 'tagged')]/following-sibling::a[not(contains(@href, 'tagged')) and not(contains(@href, '#'))]");
foreach ($nodes as $node) {
/** @var $node DOMElement */
if (preg_match('#(?:q|questions)/(?P<qid>\d+)#', $node->getAttribute('href'), $matches)) {
$qids[] = $matches['qid'];
}
}
print_r($qids);