I am doing it this way :
$dom = new DOMDocument;
$dom->loadHTMLFile("test.html");
//$books = $dom->getElementsByTagName('body');
$i = 0;
while (is_object($finance = $dom->getElementsByTagName("body")->item($i))) {
foreach ($finance->childNodes as $nodename) {
if ($nodename->childNodes) {
foreach ($nodename->childNodes as $subNodes) {
if ($subNodes->childNodes) {
foreach ($subNodes->childNodes as $potha){
echo $potha->nodeName . " - " . $potha->nodeValue . "<br>";
}
} else {
echo $subNodes->nodeName . " - " . $subNodes->nodeValue . "<br>";
}
}
} else {
echo $nodename->nodeName . " - " . $nodename->nodeValue . "<br>";
}
}
$i++;
}
But how can i make it recursive so each time when there is subChild , it should loop through each child, sub child and sub child and so on …. else echo Name of the Node and Value.
Also how can i get the position of each node relative to body or html so there is a difference between each segment.
Something like this should work for you: