user2092317
user2092317

Reputation: 3338

How to extract curl output to an array?

I am trying to convert curl output to XML for further processing like inserting into a database and showing it in the front end.

$txResult = curl_exec( $ch );
echo $txResult;
curl_close( $ch );

Output:

id=0&tId=10010&msgId=32&mText=Duplicate+record+%2D+This+recordhas+already+been+approved

I tried using this but doesn't work.

simplexml_load_string(curl_exec($ch));

Upvotes: 1

Views: 19336

Answers (1)

George Brighton
George Brighton

Reputation: 5151

That's a query string - not XML. You can use the parse_str() function to process it:

$parsed = array();
parse_str(curl_exec($ch), $parsed);
print_r($parsed);

Output:

Array
(
    [id] => 0
    [tId] => 10010
    [msgId] => 32
    [mText] => Duplicate record - This recordhas already been approved
)

Upvotes: 7

Related Questions