Well, I will introduce how to get contents of element in this article. That's why I'll show you the sample given belown.
For my example, I got two files here:
- GetContent.php
- test.html
GetContent.php
<?php
$content="test.html";
$source=new DOMdocument();
$source->loadHTMLFile($content);
$path=new DOMXpath($source);
$dom=$path->query("*/div[@id='test']");
if (!$dom==0) {
   foreach ($dom as $dom) {
      print "<br>The Type of the element is: ". $dom->nodeName. "<br><b><pre><code>";
      $getContent = $dom->childNodes;
      foreach ($getContent as $attr) {
         print $attr->nodeValue. "</code></pre></b>";
      }
   }
}
?>
test.html
<div id="test">This is my content</div>
What we have just seen up there, should be like on this demo page.
The Type of the element is: div This is my content
The result is the text above. We'll see you guys next article!

 
 
Thanks man!
ReplyDeleteThankyoy very much !
ReplyDeleteThank you! Really helpful!
ReplyDeleteThanks for Code.
ReplyDeleteKeep Writing Such Wonderful codes