Jump to content

XPath query not returning anything


Go to solution Solved by requinix,

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.