0

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 ?

1 Answer 1

2

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), ' --');
Sign up to request clarification or add additional context in comments.

4 Comments

I see, that looks legit ! Trying right now and validating your answer
That perfectly work thank you. So regarding the documentation (php.net/manual/fr/function.simplexml-load-string.php) I think they made a mistake because they use print_r($xml);
Nope -- docs look fine. They're printing the output to STDOUT. You're trying to capture it and send it to a log.
I see! My mistake then :) Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.