views:

120

answers:

2

Lots of tutorials around the net but none of them can explain me this:

How do I select a single element (in a table, for example), having its absolute XPath?

Example: I have this:

/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr/td/table[3]/tbody/tr/td/table/tbody/tr[3]/td/table/tbody/tr[4]/td[5]/span

What's that PHP function to get the text of that element?! Really I could not find an answer. Found lots of guides and hints to get all the elements of the table, all the buttons of a form, etc, but not what I need.

Thank you.

+1  A: 

Load you HTML document into a DOM object then make a DOMXPath object from it and let it evaluate your query string.

It's all described in detail here: http://php.net/manual/en/book.dom.php

Techpriester
Thank you. You both helped me.
daliz
+1  A: 
$xml = simplexml_load_string($html_content_string);
$arr = $xml->xpath("//body/table/tbody/tr[2]/td[2]/table/tbody/tr/td/table[3]/tbody/tr/td/table/tbody/tr[3]/td/table/tbody/tr[4]/td[5]/span");

var_dump($arr); 
vooD
Thank you. You both helped me.
daliz
If you like the answer then vote it up. It is better than "thank you" in comment.
vooD