Monday, September 23, 2024
Google search engine
HomeLanguagesPHP | DOMImplementation __construct() Function

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:




<?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('neveropen');
  
// 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('neveropen');
$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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments