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(); ?> |
<?xml version="1.0" encoding="iso-8859-1"?>
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(); ?> |
<?xml version="1.0" encoding="iso-8859-1"?> & < > ®
Reference: https://www.php.net/manual/en/domdocument.createentityreference.php
Recommended Posts:
- PHP | DOMDocument createTextNode() Function
- PHP | DOMDocument createComment() Function
- PHP | DOMDocument createProcessingInstruction() Function
- PHP | DOMDocument createCDATASection() Function
- PHP | DOMDocument saveHTMLFile() Function
- PHP | DOMDocument saveXML() Function
- PHP | DOMDocument __construct() Function
- PHP | DOMDocument getElementsByTagName() Function
- PHP | DOMDocument createAttribute() Function
- PHP | DOMDocument createElement() Function
- PHP | DOMDocument createAttributeNS() Function
- PHP | DOMDocument importNode() Function
- PHP | DOMDocument load() Function
- PHP | DOMDocument loadHTMLFile() Function
- PHP | DOMDocument loadHTML() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



