Saturday, November 22, 2025
HomeLanguagesPHP | DOMDocument createEntityReference() Function

PHP | DOMDocument createEntityReference() Function

The DOMDocument::createEntityReference() function is an inbuilt function in PHP which is used to create a new instance of class DOMEntityReference.

Syntax:

DOMEntityReference DOMDocument::createEntityReference( string $name )

Parameters: This function accepts single parameter $name which holds the content of the entity reference. The entity reference does not contains leading & and the trailing ; characters.

Returns Value: This function returns the new DOMEntityReference object on success or FALSE on failure.

Below programs illustrate the DOMDocument::createEntityReference() function in PHP:

Program 1:




<?php
  
// Create a new DOMDocument object
$domDocument = new DOMDocument('1.0', 'iso-8859-1');
  
// Use createEntityReference() function to create
// new entity reference node
$domER = $domDocument->createEntityReference('nbsp');
  
// Append element to the document
$domDocument->appendChild($domER);
  
// Save the XML document and display it
echo $domDocument->saveXML();
  
?>


Output:

<?xml version="1.0" encoding="iso-8859-1"?>
&nbsp;

Program 2:




<?php
  
// Create a new DOMDocument object
$domDocument = new DOMDocument('1.0', 'iso-8859-1');
  
// Use createEntityReference() function to create
// new entity reference node
$domER1 = $domDocument->createEntityReference('amp');
$domER2 = $domDocument->createEntityReference('lt');
$domER3 = $domDocument->createEntityReference('gt');
$domER4 = $domDocument->createEntityReference('reg');
  
// Append element to the document
$domDocument->appendChild($domER1);
$domDocument->appendChild($domER2);
$domDocument->appendChild($domER3);
$domDocument->appendChild($domER4);
  
// Save the XML document and display it
echo $domDocument->saveXML();
  
?>


Output:

<?xml version="1.0" encoding="iso-8859-1"?>
&amp;
&lt;
&gt;
&reg;

Reference: https://www.php.net/manual/en/domdocument.createentityreference.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS