PHP | DOMImplementation __construct() Function
Last Updated :
26 Feb, 2020
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
$documentImplementation = new DOMImplementation();
$document = $documentImplementation ->createDocument(null, 'html' );
$html = $document ->documentElement;
$heading = $document ->createElement( 'h1' );
$text = $document ->createTextNode( 'GeeksforGeeks' );
$heading ->appendChild( $text );
$html ->appendChild( $heading );
echo $document ->saveXML();
?>
|
Output:
Example 2:
<?php
$documentImplementation = new DOMImplementation();
$document = $documentImplementation ->createDocument(null, 'html' );
$html = $document ->documentElement;
$head = $document ->createElement( 'head' );
$title = $document ->createElement( 'title' );
$text = $document ->createTextNode( 'GeeksforGeeks' );
$body = $document ->createElement( 'body' );
$title ->appendChild( $text );
$head ->appendChild( $title );
$html ->appendChild( $head );
$html ->appendChild( $body );
echo $document ->saveXML();
?>
|
Output:
Reference: https://www.php.net/manual/en/domimplementation.construct.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...