Skip to content

No way to get the contents of a processing instruction in SimpleXML #12167

Closed
@nielsdos

Description

@nielsdos

Description

The following code:

<?php

$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<foo>
  <bar><?foo hello ?></bar>
</foo>
XML;

$sxe = simplexml_load_string($xml);

var_dump($sxe->xpath("//processing-instruction()")[0]->getName());
var_dump((string) $sxe->xpath("//processing-instruction()")[0]);

Resulted in this output:

string(3) "bar"
string(0) ""

But I expected this output instead:

string(3) "bar"
string(3) "hello"

PHP Version

8.1+

Operating System

Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions