DOMDocument::createEntityReference()函數是PHP中的內置函數,用於創建DOMEntityReference類的新實例。
用法:
DOMEntityReference DOMDocument::createEntityReference( string $name )
參數:該函數接受單個參數$name,該參數保存實體引用的內容。實體引用不包含&和尾隨;字符。
返回值:如果成功,此函數返回新的DOMEntityReference對象,如果失敗,則返回FALSE。
以下示例程序旨在說明PHP中的DOMDocument::createEntityReference()函數:
程序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"?>
程序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"?> & < > ®
參考: https://www.php.net/manual/en/domdocument.createentityreference.php
相關用法
- PHP DOMDocument createElement()用法及代碼示例
- PHP DOMDocument createComment()用法及代碼示例
- PHP DOMDocument createAttribute()用法及代碼示例
- PHP DOMDocument importNode()用法及代碼示例
- PHP DOMDocument createTextNode()用法及代碼示例
- PHP DOMDocument createProcessingInstruction()用法及代碼示例
- PHP DOMDocument saveXML()用法及代碼示例
- PHP DOMDocument getElementsByTagName()用法及代碼示例
- PHP DOMDocument __construct()用法及代碼示例
- PHP DOMDocument saveHTMLFile()用法及代碼示例
- PHP DOMDocument loadXML()用法及代碼示例
- PHP DOMDocument normalizeDocument()用法及代碼示例
- PHP DOMDocument loadHTMLFile()用法及代碼示例
- PHP DOMDocument saveHTML()用法及代碼示例
- PHP DOMDocument save()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DOMDocument createEntityReference() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。