PHP | DOMElement __construct() Function Last Updated : 20 Feb, 2020 Comments Improve Suggest changes Like Article Like Report The DOMElement::__construct() function is an inbuilt function in PHP which is used to create a new DOMElement object. This object is read-only and may be appended to a document, but additional nodes may not be appended to this node until the node is associated with a document. Syntax: public DOMElement::__construct( string $name, string $value, string $namespaceURI ) Parameters: This function accepts three parameters as mentioned above and described below: $name: It specifies the tag name of the element. $value (Optional): It specifies the value of the element. $namespaceURI (Optional): It specifies the namespace URI to create the element within a specific namespace. Below given programs illustrate the DOMElement::__construct() function in PHP: Program 1: php <?php // Create a new DOMDocument $dom = new DOMDocument(); // Append a new Child which is a DOMElement $element = $dom->appendChild(new DOMElement('root')); // Create another h1 element using // DOMElement constructor $element_new = new DOMElement('h1', 'Heading', 'http://sample_url'); // Append the child $element->appendChild($element_new); // Save the XML echo $dom->saveXML(); ?> Output: <?xml version="1.0"?> <root><h1 xmlns="http://sample_url">Heading</h1></root> Program 2: php <?php // Create a new DOMDocument $dom = new DOMDocument(); // Append a new Child which is a DOMElement $element = $dom->appendChild(new DOMElement('root')); // Create another DOMElement for mark $element_mark = new DOMElement('mark', 'Marked'); // Append the child $element->appendChild($element_mark); // Create another DOMElement for break $element_break = new DOMElement('br'); // Append the child $element->appendChild($element_break); // Create another DOMElement for delete $element_delete = new DOMElement('del', 'Deleted'); // Append the child $element->appendChild($element_delete); // Create another DOMElement for break $element_break = new DOMElement('br'); // Append the child $element->appendChild($element_break); // Create another DOMElement for bold $element_bold = new DOMElement('b', 'Bold'); // Append the child $element->appendChild($element_bold); // Save the XML echo $dom->saveXML(); ?> Output: <?xml version="1.0"?> <root> <mark>Marked</mark><br/> <del>Deleted</del><br/> <b>Bold</b> </root> Reference: https://www.php.net/manual/en/domelement.construct.php Comment More infoAdvertise with us Next Article PHP | DOMElement __construct() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMComment __construct() Function The DOMComment::__construct() function is an inbuilt function in PHP which creates a new DOMComment object. This object is read only and can be appended to a document Syntax: public DOMComment::__construct( string $value) Parameters: This function accepts a single parameter $value which holds the co 1 min read PHP | DOMDocument __construct() Function The DOMDocument::__construct() function is an inbuilt function in PHP which is used to create a new DOMDocument object. Syntax: public DOMDocument::__construct( string $version, string $encoding ) Parameters: This function accepts two parameters as mentioned above and described below: $version: This 1 min read PHP | DOMImplementation __construct() Function The DOMImplementation::__construct() function is an inbuilt function in PHP which is used to create a new DOMImplementation object. Syntax: DOMImplementation::__construct( void ) Parameters: This function doesnât accept any parameter. Below examples illustrate the DOMImplementation::__construct() fu 1 min read PHP | DOMAttr __construct() Function The DOMAttr::__construct() function is an inbuilt function in PHP which is used to create a new DOMAttr object. This created object is a read-only type. Syntax: public DOMAttr::__construct( string $name, string $value ) Parameters: This function accepts two parameters as mentioned above and describe 2 min read PHP | DOMEntityReference __construct() function The DOMEntityReference::__construct() function is an inbuilt function in PHP which is used to create a new DOMEntityReference object. Syntax: public DOMEntityReference::__construct( string $name ) Parameters:This function accepts a single parameter $name which holds the name of the entity reference. 1 min read Like