Open In App

PHP | DOMImplementation __construct() Function

Last Updated : 26 Feb, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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() function in PHP:

Example 1:




<?php
  
// Create a DOMImplementation instance
$documentImplementation = new DOMImplementation();
  
// Create a document
$document = $documentImplementation->createDocument(null, 'html');
  
// Get the document element
$html = $document->documentElement;
  
// Create few element
$heading = $document->createElement('h1');
$text = $document->createTextNode('GeeksforGeeks');
  
// Append the children
$heading->appendChild($text);
$html->appendChild($heading);
  
// Render the XML
echo $document->saveXML();
?>


Output:

Example 2:




<?php
// Create a DOMImplementation instance
$documentImplementation = new DOMImplementation();
  
// Create a document
$document = $documentImplementation->createDocument(null, 'html');
  
// Get the document element
$html = $document->documentElement;
  
// Create few element
$head = $document->createElement('head');
$title = $document->createElement('title');
$text = $document->createTextNode('GeeksforGeeks');
$body = $document->createElement('body');
  
// Append the children
$title->appendChild($text);
$head->appendChild($title);
$html->appendChild($head);
$html->appendChild($body);
  
// Render the XML
echo $document->saveXML();
?>


Output:

Reference: https://www.php.net/manual/en/domimplementation.construct.php



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads