0
<entry>
    <string>actiontypedesc</string>
    <string>Registration of google1231.com for 1 year</string>
</entry>
<entry>
    <string>unutilisedsellingamount</string>
    <string>-1531.770</string>
</entry>
<entry>
    <string>sellingamount</string>
    <string>-1531.770</string>
</entry>
<entry>
    <string>entityid</string>
    <string>57928339</string>
</entry>
<entry>
    <string>actionstatus</string>
    <string>Success</string>
</entry>`

this is the output after the API call how do i convert it into the array?

5
  • 1
    And what have you tried so far? Or should we just do your entire work? (Which we won't) Commented Dec 13, 2014 at 9:13
  • $xml = simplexml_load_string($store_array); $json = json_encode($xml); $array = json_decode($json,true); var_dump($array); Commented Dec 13, 2014 at 9:14
  • Then edit your question and show what you have tried so we see that you have tried something! Commented Dec 13, 2014 at 9:15
  • I'll recommend you read about it : JSON Commented Dec 13, 2014 at 9:15
  • An array of what? XML array? JSON array? JavaScript object array? .NET object array. Commented Dec 13, 2014 at 9:20

1 Answer 1

4

Can try using simplexml_load_string(). Enclose your whole xml by a parent tag. Here I included <myxml>...</myxml>. Example:

$myXMLData =
"<?xml version='1.0' encoding='UTF-8'?>
<myxml>
<entry>
    <string>actiontypedesc</string>
    <string>Registration of google1231.com for 1 year</string>
</entry>
<entry>
    <string>unutilisedsellingamount</string>
    <string>-1531.770</string>
</entry>
<entry>
    <string>sellingamount</string>
    <string>-1531.770</string>
</entry>
<entry>
    <string>entityid</string>
    <string>57928339</string>
</entry>
<entry>
    <string>actionstatus</string>
    <string>Success</string>
</entry>
</myxml>";

$xml = json_decode(json_encode(simplexml_load_string($myXMLData)), true);
// json_encode() & json_decode() is to convert object to array
print '<pre>';
print_r($xml);
print '</pre>';
Sign up to request clarification or add additional context in comments.

Comments

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.