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
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS