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 Link to comment https://forums.phpfreaks.com/topic/284716-xpath-query-not-returning-anything/ Share on other sites More sharing options...
requinix Posted December 11, 2013 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. 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 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
Archived
This topic is now archived and is closed to further replies.