PHP 8.5.0 Beta 3 available for testing

DOMDocument::createProcessingInstruction

(PHP 5, PHP 7, PHP 8)

DOMDocument::createProcessingInstruction โ€” ๆ–ฐใ—ใ„ PI ใƒŽใƒผใƒ‰ใ‚’ไฝœๆˆใ™ใ‚‹

่ชฌๆ˜Ž

public DOMDocument::createProcessingInstruction(string $target, string $data = ""): DOMProcessingInstruction|false

ใ“ใฎ้–ขๆ•ฐใฏใ€DOMProcessingInstruction ใ‚ฏใƒฉใ‚นใฎๆ–ฐใ—ใ„ใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใ‚’ไฝœๆˆใ—ใพใ™ใ€‚ใ“ใฎใƒŽใƒผใƒ‰ใฏใ€( DOMNode::appendChild() ใชใฉใง) ๆŒฟๅ…ฅใ•ใ‚Œใชใ„้™ใ‚Šใ€ใƒ‰ใ‚ญใƒฅใƒกใƒณใƒˆๅ†…ใซใ‚ใ‚‰ใ‚ใ‚Œใพใ›ใ‚“ใ€‚

ใƒ‘ใƒฉใƒกใƒผใ‚ฟ

target

ๅ‡ฆ็†ๅ‘ฝไปคใฎๅฏพ่ฑกใ€‚

data

ๅ‡ฆ็†ๅ‘ฝไปคใฎๅ†…ๅฎนใ€‚

ๆˆปใ‚Šๅ€ค

ๆ–ฐใ—ใ„ DOMProcessingInstructionใ€ ใ‚ใ‚‹ใ„ใฏใ‚จใƒฉใƒผใŒ็™บ็”Ÿใ—ใŸๅ ดๅˆใซใฏ false ใ‚’่ฟ”ใ—ใพใ™ใ€‚

ใ‚จใƒฉใƒผ / ไพ‹ๅค–

DOM_INVALID_CHARACTER_ERR

target ใŒ็„กๅŠนใชๆ–‡ๅญ—ใ‚’ๅซใ‚“ใงใ„ใ‚‹ๅ ดๅˆใซ็™บ็”Ÿใ—ใพใ™ใ€‚

ๅ‚่€ƒ

๏ผ‹add a note

User Contributed Notes 1 note

up
4
romain at supinfo dot com ยถ
16 years ago
A use exemple of this method :

Usefull for generating an XML linked with a XSLT !

<?php

// "Create" the document.
$xml = new DOMDocument( "1.0", "ISO-8859-15" );

//to have indented output, not just a line
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;

// ------------- Interresting part here ------------

//creating an xslt adding processing line
$xslt = $xml->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="base.xsl"');

//adding it to the xml
$xml->appendChild($xslt);

// ----------- / Interresting part here -------------

//adding some elements
$root = $xml->createElement("list");
$node = $xml->createElement("contact", "John Doe");
$root-> appendChild($node);
$xml-> appendChild($root);

//creating the file
$xml-> save("output.xml");

?>

output.xml :

<?xml version="1.0" encoding="ISO-8859-15"?>
<?xml-stylesheet type="text/xsl" href="base.xsl"?> //the line has been created successfully
<list>
<contact>John Doe</contact>
</list>
To Top