KapaGino Posted December 11, 2013 Share Posted December 11, 2013 Hiya, I'm trying to learn the basics of XPath but I'm having trouble getting it to return anything. All I want is for it to grab the title of the page and echo it... <?php $doc = new DOMDocument(); $doc->loadHTML("http://www.estatesgazette.com/propertylink/advert/4th_floor_pear_mill_industrial_estate_stockport_cheshire-stockport_cheshire-3383230.htm"); $xpath = new DOMXPath($doc); $nodes = $xpath->query("/html/head/title"); $title = $nodes->item(0)->nodeValue; echo $title; ?> I'm running PHP 5.4.7 btw Thanks Quote Link to comment https://forums.phpfreaks.com/topic/284716-xpath-query-not-returning-anything/ Share on other sites More sharing options...
Solution requinix Posted December 11, 2013 Solution Share Posted December 11, 2013 Your use of XPath is right. Your use of DOMDocument is not. $doc->loadHTML(That loads an HTML string. You want loadHTMLFile which loads HTML from a location. Quote Link to comment https://forums.phpfreaks.com/topic/284716-xpath-query-not-returning-anything/#findComment-1462132 Share on other sites More sharing options...
Barand Posted December 11, 2013 Share Posted December 11, 2013 try include ('simple_html_dom.php'); $doc = file_get_html("http://www.estatesgazette.com/propertylink/advert/4th_floor_pear_mill_industrial_estate_stockport_cheshire-stockport_cheshire-3383230.htm"); $title = $doc->find('title',0); echo $title->plaintext; I remember the Pear Mill, and the Welkin Mill across the road, when they were mills Quote Link to comment https://forums.phpfreaks.com/topic/284716-xpath-query-not-returning-anything/#findComment-1462135 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.