Jump to content

XPath query not returning anything


KapaGino

Recommended Posts

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 :happy-04:

Link to comment
https://forums.phpfreaks.com/topic/284716-xpath-query-not-returning-anything/
Share on other sites

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.