©
This document uses PHP Chinese website manual Release
(PHP 5, PHP 7)
DOMDocument::createEntityReference — Create new entity reference node
$name
)This function creates a new instance of class DOMEntityReference. 此节点出现在文档中,除非是用诸如 DOMNode->appendChild() 等函数来将其插入。
name
The content of the entity reference, e.g. the entity reference minus the leading & and the trailing ; characters.
The new DOMEntityReference or FALSE
if an error
occurred.
DOM_INVALID_CHARACTER_ERR
Raised if name
contains an invalid character.
[#1] alicewonder at shastaherps dot org [2015-09-24 19:48:24]
It appears that this does not work with numbered entities, only named entities.
$nbspace = $dom->createEntityReference('nbsp');
works
$nbspace = $dom->createEntityReference('#160');
does not. This makes this function rather useless when generating an XSL unless you modify the XSL doctype to include the named entity for the character you want.
[#2] Tuhin Bepari [2013-11-04 06:00:11]
<?php
$dom=new DOMDocument("1.0","UTF-8");
$example=$dom->createElement("example","This is copyright ");
$entity=$dom->createEntityReference("copy");
$example->appendChild($entity);
$dom->appendChild($example);
echo $dom->saveXML();
output is
This is copyright ?