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


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

DOMProcessingInstruction::__construct()函數是PHP中的內置函數,該函數使用新的隻讀DOMProcessingInstruction對象。要創建可寫節點,請使用DOMDocument::createProcessingInstruction。

用法:

public DOMProcessingInstruction::__construct( string $name, string $value )

參數:該函數接受上述和以下所述的兩個參數:



  • $name:它指定處理指令的標簽名稱。
  • $value:它指定處理指令的值。

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

程序1:按Ctrl + U查看DOM

<?php 
  
// Create a new DOMDocument instance 
$dom = new DOMDocument(); 
  
// Create a html element 
$html = $dom->appendChild(new DOMElement('html')); 
  
// Create a body element 
$body = $html->appendChild(new DOMElement('body')); 
  
// Create a new DOMProcessingInstruction node 
$pinode = new DOMProcessingInstruction('php', 
          'echo "GeeksforGeeks"; '); 
  
// Append the child 
$body->appendChild($pinode); 
  
// Render the XML 
echo $dom->saveXML(); 
?>

輸出:

程序2:按Ctrl + U查看DOM元素。

<?php 
  
// Create a new DOMDocument instance 
$dom = new DOMDocument(); 
  
// Create a html element 
$html = $dom->appendChild(new DOMElement('html')); 
  
// Create a body element 
$body = $html->appendChild(new DOMElement('body')); 
  
// Create a new DOMProcessingInstruction node 
$pinode = new DOMProcessingInstruction('xml-stylesheet', 
       'type="text/xsl" href="base.xsl"'); 
  
// Append the child 
$body->appendChild($pinode); 
  
// Render the XML 
echo $dom->saveXML(); 
?>

輸出:

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




相關用法


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