PHP DOM is returning all the nodes even if I am in a specific tag. I have been trying to solve this thing for around 2 weeks now but no progress. Please help.
Here is my code:
$dom = new DOMDocument;
$dom->loadhtmlfile($url);
$doc=$dom->documentElement;
$res = $doc->getElementsByTagName('td')->item(54);
$tables = $res->getElementsByTagName('table'); //Here it returns every 'table', not just the ones which are under that 'td'
From the documentation: getElementsByTagName — Searches for all elements with given local tag name
If you want to find the table inside a ‘td’ element, use a XPath query.