tags:

views:

42

answers:

2

I'm receiving XML sent via POST. Naturally I need to parse this XML to get at the goodies it holds for me. However, when I receive the XML is seems that PHP is parsing it like a query string.

For example, this xml:

<?xml version="1.0" encoding="utf-8"?>
<ForgotPassword>
    <version>1.0</version>
    <authentication>
        <login>myresllerid</login>
        <apikey>1234567890abcdef</apikey>
    </authentication>
    <parameters>
        <emailAddress>[email protected]</emailAddress>
    </parameters>
</ForgotPassword>

Becomes this (from print_r($_REQUEST)):

Array
(
    [
<?xml_version] => "1.0" encoding="utf-8"?>
<IDCForgotPassword>
    <version>1.0</version>
    <authentication>
        <login>myresllerid</login>
        <apikey>1234567890abcdef</apikey>
    </authentication>
    <parameters>
        <emailAddress>[email protected]</emailAddress>
    </parameters>
</IDCForgotPassword>
)

You can see the XML is being broken up at the first equals sign (=) in the XML into a key/value pair.

How do I avoid this?

A: 

you need to use http://php.net/manual/en/function.simplexml-load-string.php SimpleXML Load String for parsing properly.

Osman Üngür
+2  A: 

Unless enctype is multipart/form-data use php://input to fetch the raw input.

$c = file_get_contents('php://input');
VolkerK