(PHP 5, PHP 7, PHP 8)
DOMProcessingInstruction::__construct — 建立新的 DOMProcessingInstruction 物件
建立一個新的 DOMProcessingInstruction 物件。此物件為唯讀。它可以被附加到文件中,但在節點與文件關聯之前,不能將其他節點附加到此節點。要建立可寫入的節點,請使用 DOMDocument::createProcessingInstruction。
name
處理指令的標籤名稱。
value
處理指令的值。
範例 #1 建立一個新的 DOMProcessingInstruction 物件
<?php
$dom = new DOMDocument('1.0', 'UTF-8');
$html = $dom->appendChild(new DOMElement('html'));
$body = $html->appendChild(new DOMElement('body'));
$pinode = new DOMProcessingInstruction('php', 'echo "Hello World"; ');
$body->appendChild($pinode);
echo $dom->saveXML();
?>
以上範例會輸出:
<?xml version="1.0" encoding="UTF-8"?> <html><body><?php echo "Hello World"; ?></body></html>