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

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.