I have an HTML document for example:
<!DOCTYPE html>
<html>
<head>
<title>Webpage</title>
</head>
<body>
<div class="content">
<div>
<p>Paragraph</p>
</div>
<div>
<a href="someurl">This is an anchor</a>
</div>
<p>This is a paragraph inside a div</p>
</div>
</body>
</html>
I want to grab exact structure of the div having class of content
.
Using DomDocument in PHP if I fetch the div using the getElementsByTagName()
method, I am getting this:
DOMElement Object
(
[tagName] => div
[schemaTypeInfo] =>
[nodeName] => div
[nodeValue] =>
Paragraph
This is an anchor
This is a paragraph inside a div
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] => (object value omitted)
[nextSibling] => (object value omitted)
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => div
[baseURI] =>
[textContent] =>
Paragraph
This is an anchor
This is a paragraph inside a div
)
How can I get this instead:
<div class="content">
<div>
<p>Paragraph</p>
</div>
<div>
<a href="someurl">This is an anchor</a>
</div>
<p>This is a paragraph inside a div</p>
</div>
Is there any way of doing this?