PHP Conference Japan 2024

DOMProcessingInstruction::__construct

(PHP 5, PHP 7, PHP 8)

DOMProcessingInstruction::__construct 建立新的 DOMProcessingInstruction 物件

說明

public DOMProcessingInstruction::__construct(字串 $name, 字串 $value = "")

建立一個新的 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>

另請參閱

新增註記

使用者貢獻的註記

此頁面沒有使用者貢獻的註記。
To Top