And Row ID
And Row ID

Reputation: 197

simplexml_load_string cannot load XML / No error / result not === false

XML:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<result sync="false" version="2">
    <action>start-subscription</action>
    <action_result>
        <code>103</code>
        <detail>1 missing parameter</detail>
        <missing_parameters>
            <missing_parameter>
                <key>operator</key>
            </missing_parameter>
        </missing_parameters>
        <status>1</status>
    </action_result>
    <custom_parameters>
        <custom_parameter>
            <key>cp_REF</key>
            <value>simpleLPADULTCHSMSV2___WoopGang------___Adjomo___external___paid___android___CH___WIFI___locale=fr_FR</value>
        </custom_parameter>
    </custom_parameters>
    <customer>
        <country>CH</country>
        <language>en</language>
    </customer>
    <payment_parameters>
        <channel>web</channel>
        <method>OPERATOR</method>
        <order>90330</order>
    </payment_parameters>
    <transactions>
        <transaction>
            <id>1308636894</id>
            <status>-1</status>
        </transaction>
    </transactions>
    <request_id>1591621_t593818e0f3913</request_id>
    <reference>09045c8e-9ec1-4306-8699-5ac5306983b2</reference>
</result>

PHP:

    $xml = file_get_contents("php://input");
    $datas = array();
    parse_str($xml, $datas);
    $data = $datas['data'];
    libxml_use_internal_errors(true);

    $xml = simplexml_load_string($data);

    if($xml === false){
        foreach(libxml_get_errors() as $error) {
            $this->_logCall(self::LOG_DIMOCO, $error->message,"--");
         }
     }else{
         $this->_logCall(self::LOG_DIMOCO, 'loaded simpleXML '.print_r($xml), ' --');
     }      

Running that ends in the last ELSE and the result is "1"

Any idea what I'm doing wrong ? I have to add some text because apparently its mostly code and not understandable. Now ? Now ? Now ? Now ?

Upvotes: 0

Views: 499

Answers (1)

Alex Howansky
Alex Howansky

Reputation: 53573

print_r() (by default) doesn't return output, it prints it -- so you can't use it in a string context. If you want to do that, you can pass a truthy value as the second parameter to have it return the output instead of printing it:

$this->_logCall(self::LOG_DIMOCO, 'loaded simpleXML '.print_r($xml, true), ' --');

Upvotes: 2

Related Questions