CakeFest 2024: The Official CakePHP Conference

DOMProcessingInstruction::__construct

(PHP 5, PHP 7, PHP 8)

DOMProcessingInstruction::__construct 新しい DOMProcessingInstruction オブジェクトを作成する

説明

public DOMProcessingInstruction::__construct(string $name, string $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>

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top