// Load the HTML document $html = file_get_contents('example.html'); $doc = new DOMDocument(); $doc->loadHTML($html); // Get all "p" elements $paragraphs = $doc->getElementsByTagName('p'); // Loop through each "p" element foreach ($paragraphs as $p) { echo $p->nodeValue . "
"; }
// Load the XML document $xml = file_get_contents('example.xml'); $doc = new DOMDocument(); $doc->loadXML($xml); // Get all "title" elements $titles = $doc->getElementsByTagName('title'); // Loop through each "title" element foreach ($titles as $title) { echo $title->nodeValue . "This example demonstrates how to extract all the "title" elements from an XML document and print their inner text content using the DOMNode getElementsByTagName() method. The PHP DOMNode getElementsByTagName() method is part of the PHP DOM extension and requires no additional package or library.
"; }