PHP | DOMEntityReference __construct() function
Last Updated :
19 Feb, 2020
Improve
The DOMEntityReference::__construct() function is an inbuilt function in PHP which is used to create a new DOMEntityReference object.
Syntax:
php
Output:
Program 2:
php
Output:
public DOMEntityReference::__construct( string $name )Parameters:This function accepts a single parameter $name which holds the name of the entity reference. Below given programs illustrate the DOMEntityReference::__construct() function in PHP: Program 1:
<?php
// Create a new DOMDocument
$dom = new DOMDocument();
// Add the node to the dom
$element = $dom->appendChild(new DOMElement('H1'));
// Add the DOM Entity Reference as a child
$entity = $element->appendChild(new DOMEntityReference('GeeksforGeeks'));
// Render the XML
echo $dom->saveXML();
?>

<?php
// Create a new DOMDocument
$dom = new DOMDocument();
// Add the node to the dom
$element = $dom->appendChild(new DOMElement('body'));
// Add the DOM Entity Reference as a child
$entity = $element->appendChild(new DOMEntityReference('GeeksforGeeks'));
// View the name of node
echo $entity->nodeName;
?>
GeeksforGeeksReference: https://www.php.net/manual/en/domentityreference.construct.php