1

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));
1
  • 1
    Please avoid the phrase "doesn't work", you risk getting downvoted for it. Here's why: whenever people use the phrase, they often forget to mention what they expected to happen, and what actually happened. In this case, the problem was clear, but in general people will respond asking whether you received errors/warnings, what the output was, whether there's any issues in your logs etc. Save them the bother and add all that in first time around! Commented Oct 4, 2013 at 18:17

1 Answer 1

7

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

1 Comment

thanks for the quick response. I think i have to change the question name "How to Extract curl output to array?"

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.