array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'domprocessinginstruction.construct.php', 1 => 'DOMProcessingInstruction::__construct', ), 'up' => array ( 0 => 'class.domprocessinginstruction.php', 1 => 'DOMProcessingInstruction', ), 'prev' => array ( 0 => 'class.domprocessinginstruction.php', 1 => 'DOMProcessingInstruction', ), 'next' => array ( 0 => 'class.domtext.php', 1 => 'DOMText', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/dom/domprocessinginstruction/construct.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(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>