$doc = new DOMDocument(); $pi = $doc->createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"'); $doc->appendChild($pi);
$doc = new DOMDocument(); $pi = $doc->createProcessingInstruction('mytarget', 'mydata'); $doc->appendChild($pi);This code creates a new processing instruction node with the target "mytarget" and data "mydata". It then appends the node to the document. These examples use PHP's built-in DOMDocument class, which is part of the PHP Standard Library. No external package or library is required to use these methods.