I am trying to get some contents from one html file and load that content into another html file using php. I have loaded the first html file as DOMdocument. Now I would like to get the contents inside a certain tag of that loaded html file. I have searched for the solution in the internet but I could only find the methods to get the value of content inside the tag. I would like to get all the contents inside the given tag. i.e including the inner html tags. How can i do it?
I have a html file like this:
<html>
<head>
</head>
<body>
</body>
<p>
<h1> hi </h1>
</p>
</html>
A domdocument is created using this html file. Now what i would like to do is get the contents:
<p>
<h1> hi </h1>
</p>
as a string.
In short, I am in need of a function something like :
$doc->getElementsByTagName('p').item(0).innerHTML;
Here $doc is a DomDocument.
$doc = new DomDocument;
$doc->Load('test.html');