$doc = new DOMDocument(); $element = new DOMElement("div", "Hello World"); $doc->appendChild($element);
$doc = new DOMDocument(); $element = new DOMElement("img"); $element->setAttribute("src", "image.jpg"); $doc->appendChild($element);Brief Explanation: Example 1 creates a new "div" element with inner text "Hello World" and appends it to a new DOMDocument instance. Example 2 creates a new "img" element with the "src" attribute set to "image.jpg" and appends it to a new DOMDocument instance. Package Library: This method is part of the PHP Standard Library.