HomeLanguagesPHP | DOMEntityReference __construct() function

PHP | DOMEntityReference __construct() function

The DOMEntityReference::__construct() function is an inbuilt function in PHP which is used to create a new DOMEntityReference object.

Syntax:

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('neveropen'));
  
// Render the XML
echo $dom->saveXML();
?>


Output:

Program 2:




<?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('neveropen'));
  
// View the name of node
echo $entity->nodeName;
?>


Output:

neveropen

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

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32715 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7093 POSTS0 COMMENTS
Nicole Veronica
12231 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12314 POSTS0 COMMENTS
Shaida Kate Naidoo
7209 POSTS0 COMMENTS
Ted Musemwa
7473 POSTS0 COMMENTS
Thapelo Manthata
7193 POSTS0 COMMENTS
Umr Jansen
7173 POSTS0 COMMENTS