Answer the question
In order to leave comments, you need to log in
How to get the entire content of an element using xpath?
How to get not just the text content of this or that element using the xpath request, but everything that it contains, including nested tags and their attributes, for example, if I access the block using the //div request, I get only its text and if there is a link in the block, then as a result I will get only the text content of the link, and not its href attribute, but I would like to get all the nested elements and their attributes.
Answer the question
In order to leave comments, you need to log in
Here is a working solution
<?php
function getInnerHTML($node)
{
$children = $node->childNodes;
foreach ($children as $child)
{
$tmp_doc = new DOMDocument();
$tmp_doc->appendChild($tmp_doc->importNode($child,true));
$innerHTML .= $tmp_doc->saveHTML();
}
return $innerHTML;
}
?>
In xpath, besides the textContent parameter, there are others, for example, innerHTML. Look in their direction.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question