tags:

views:

259

answers:

2

Hi

I have this URL:-

http://ask.recipelabs.com/users

and I wish to find the highest page number in the div id 'pager' (in this case it is 7)

I have tried this but it returns zero:

function getusers($url)
{
$doc = new DOMDocument;
$doc->loadhtml($url);
$xpath = new DOMXPath($doc);
$nodelist = $xpath->query('//span[@class="page-numbers"]');
echo 'there are ', $nodelist->length, ' span elements having class="page-numbers"';
}

Is my syntax incorrect? I was then hoping to step through the array and find the highest number.

Thanks

Jonathan

A: 

You could try:

(//span[@class="page-numbers"][number(.) > 0])[last()]

This gives you the one last node that still has a number as it's contents.

Tomalak
that doesn't appear to work - could you try it with he URL I included and the full function I supplied?
Jonathan Lyon
the array is empty
Jonathan Lyon
A: 

The problem is that you are using

$doc->loadhtml($url);

And unless $url is badly named, it is a string containing a URL, not HTML. Such a string parses a pretty much an empty DOM, certainly not one with all the expected XPath, et voila...

Maybe you meant $doc = loadHTMLFile($url); ?

mjv