There is xml coming with CURL:

<?xml version="1.0"?> <merchant.response> <operation wmtransid="782312540" wminvoiceid="336870756"> <amount>1</amount> <operdate>20121126 03:57:10</operdate> <purpose>test</purpose> <pursefrom>R256020338309</pursefrom> </operation> <retval>0</retval> <retdesc></retdesc> </merchant.response> $result = curl_exec($ch); 

All attempts to parse are unsuccessful.

 $xml = new SimpleXMLElement($result); print_r($xml); 

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/user1734/public_html/system/modules/settings/balance/info_xml.php:22 Stack trace: #0 /home/user1734/public_html/system/modules/settings/balance/info_xml.php(22): SimpleXMLElement->__construct('1') #1 {main} thrown in /home/user1734/public_html/system/modules/settings/balance/info_xml.php on line 22

What is the problem?

  • How to curl_exec ($ ch) is initialized by $ ch and what options does curl have? The fact is that you do not return the XML code, but the "1". - KryDos

1 answer 1

When you call curl_exec ($ ch), you return the status and not the string with XML.

You need to do curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); to return the result to the $ result variable.

Here you can see a list of all options.

  • one
    @KryDos, always knew that HashCode is smart people :) Thank you! - ModaL