PHP 8.5.0 Beta 3 available for testing

DOMDocument::createEntityReference

(PHP 5, PHP 7, PHP 8)

DOMDocument::createEntityReference โ€” ๆ–ฐใ—ใ„ใ‚จใƒณใƒ†ใ‚ฃใƒ†ใ‚ฃๅ‚็…งใƒŽใƒผใƒ‰ใ‚’ไฝœๆˆใ™ใ‚‹

่ชฌๆ˜Ž

public DOMDocument::createEntityReference(string $name): DOMEntityReference|false

ใ“ใฎ้–ขๆ•ฐใฏใ€DOMEntityReference ใ‚ฏใƒฉใ‚นใฎๆ–ฐใ—ใ„ใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใ‚’ไฝœๆˆใ—ใพใ™ใ€‚ใ“ใฎใƒŽใƒผใƒ‰ใฏใ€( DOMNode::appendChild() ใชใฉใง) ๆŒฟๅ…ฅใ•ใ‚Œใชใ„้™ใ‚Šใ€ใƒ‰ใ‚ญใƒฅใƒกใƒณใƒˆๅ†…ใซใ‚ใ‚‰ใ‚ใ‚Œใพใ›ใ‚“ใ€‚

ใƒ‘ใƒฉใƒกใƒผใ‚ฟ

name

ใ‚จใƒณใƒ†ใ‚ฃใƒ†ใ‚ฃๅ‚็…งใฎๅ†…ๅฎนใ€ใคใพใ‚Šใ€ใ‚จใƒณใƒ†ใ‚ฃใƒ†ใ‚ฃๅ‚็…งใ‹ใ‚‰ ๅ…ˆ้ ญใฎ & ใŠใ‚ˆใณๆœซๅฐพใฎ ; ใ‚’ๅ–ใ‚Š้™คใ„ใŸใ‚‚ใฎใ€‚

ๆˆปใ‚Šๅ€ค

ๆ–ฐใ—ใ„ DOMEntityReferenceใ€ ใ‚ใ‚‹ใ„ใฏใ‚จใƒฉใƒผใŒ็™บ็”Ÿใ—ใŸๅ ดๅˆใซใฏ false ใ‚’่ฟ”ใ—ใพใ™ใ€‚

ใ‚จใƒฉใƒผ / ไพ‹ๅค–

DOM_INVALID_CHARACTER_ERR

name ใŒ็„กๅŠนใชๆ–‡ๅญ—ใ‚’ๅซใ‚“ใงใ„ใ‚‹ๅ ดๅˆใซ็™บ็”Ÿใ—ใพใ™ใ€‚

ๅ‚่€ƒ

๏ผ‹add a note

User Contributed Notes 2 notes

up
3
alicewonder at shastaherps dot org ยถ
9 years ago
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.
up
0
Tuhin Bepari ยถ
11 years ago
<?php
/*Entity is a group of words which print a special symbol.
Like if we want to show copy right symbol in html page then we use &copy; code and browser convert this to actual copyright symbol.
There have lots of entity, you can find them all form http://dev.w3.org/html5/html-author/charref
if you want to use < or > or both <> into a node value than xml will give and warning or make this value as a node.
So tell the xml parser that < or > is not tag symbol it is a entity.To do that you have to right &lt(<) and &gt;(>) instead of < and > symbol.

Entity references always begin with an ampersand (&) and end with a semicolon (;).
DO not need to use & and ; symbol begin and end of entity.Remove it when you want to use it to DOMDocument::createEntityReference
Then append to to a tag where you want to show this symbol.Like below
*/
$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 ยฉ
To Top