src/SimpleDOM.php
public function insertPI($target, $data = null, $mode = 'before')
    {
        $tmp = dom_import_simplexml($this);
        $doc = $tmp->ownerDocument;

        if (isset($data)) {
            if (is_array($data)) {
                $str = '';
                foreach ($data as $k => $v) {
                    $str .= $k . '="' . htmlspecialchars($v) . '" ';
                }

                $data = substr($str, 0, -1);
            } else {
                $data = (string)$data;
            }

            $pi = $doc->createProcessingInstruction($target, $data);
        } else {
            $pi = $doc->createProcessingInstruction($target);
        }

        if ($pi !== false) {
            $this->insertNode($tmp, $pi, $mode);
        }

        return $this;
    }
public function insertPI($target, $data = null, $mode = 'before')
    {
        $tmp = dom_import_simplexml($this);
        $doc = $tmp->ownerDocument;

        if (isset($data)) {
            if (is_array($data)) {
                $str = '';
                foreach ($data as $k => $v) {
                    $str .= $k . '="' . htmlspecialchars($v) . '" ';
                }

                $data = substr($str, 0, -1);
            } else {
                $data = (string)$data;
            }

            $pi = $doc->createProcessingInstruction($target, $data);
        } else {
            $pi = $doc->createProcessingInstruction($target);
        }

        if ($pi !== false) {
            $this->insertNode($tmp, $pi, $mode);
        }

        return $this;
    }
Insert a Processing Instruction

The content of the PI can be passed either as string or as an associative array.

@param    string $target Target of the processing instruction
@param    string|array $data Content of the processing instruction
@param string $mode
@throws BadMethodCallException
@return    bool                        TRUE on success, FALSE on failure