Here is a one liner for using XPATH with HTML in PHP
$doc = new DOMXPath(@DOMDocument::loadHTML(file_get_contents("https://www.reddit.com/r/PHP/")));
Now you can use XPATH to query the html..
foreach($doc->query("//a") as $el){
echo $el->nodeValue . " " . $el->getAttribute("href") . "\n";
}
Just finishing up brewing up some fresh ground comments...