當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP DOMEntityReference __construct()用法及代碼示例

DOMEntityReference::__construct()函數是PHP中的內置函數,用於創建新的DOMEntityReference對象。

用法:

public DOMEntityReference::__construct( string $name )

參數:該函數接受單個參數$name,該參數保存實體引用的名稱。


下麵給出的程序說明了PHP中的DOMEntityReference::__construct()函數:

程序1:

<?php 
// Create a new DOMDocument 
$dom = new DOMDocument(); 
  
// Add the node to the dom 
$element = $dom->appendChild(new DOMElement('H1')); 
    
// Add the DOM Entity Reference as a child 
$entity = $element->appendChild(new DOMEntityReference('GeeksforGeeks')); 
  
// Render the XML 
echo $dom->saveXML(); 
?>

輸出:

程序2:

<?php 
// Create a new DOMDocument 
$dom = new DOMDocument(); 
  
// Add the node to the dom 
$element = $dom->appendChild(new DOMElement('body')); 
    
// Add the DOM Entity Reference as a child 
$entity = $element->appendChild(new DOMEntityReference('GeeksforGeeks')); 
  
// View the name of node 
echo $entity->nodeName; 
?>

輸出:

GeeksforGeeks

參考: https://www.php.net/manual/en/domentityreference.construct.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | DOMEntityReference __construct() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。