Xpath is apowerful method available in php to select specific elemts in the DOM structure of any xml document, and also html document. The code below can be used for example to check for back links, in a robust way. The code below allows for back links to any page or subpage on your domain, but can easily be changed to be more discriminating.
$page = file_get_contents('http://www.pagetobechecked.com'); $dom = new DOMDocument(); @$dom->loadHTML($page); $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a[substring(@href,1,25)='http://www.yourdomain.com']"); if($hrefs->length>0) {$link_exists = true;} else {$link_exists = false;} }
Popularity: 6% [?]