Get one item with PHP and XPath

A lot of tutorials on the net, but not one of them can explain this to me:

How to select one element (for example, in a table) having 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 / mp [4] / td [5] / range

What is this PHP function to get the text of this element ?! In fact, I could not find the answer. Found a lot of guides and tips to get all the elements of the table, all the buttons of the form, etc., But not what I need.

Thank.

+3
source share
2 answers
+2
$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); 
+5

Source: https://habr.com/ru/post/1739837/


All Articles