0

I have an XML that's coming back from an cURL post that's returning:

$output=<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mtMessageRsp carrier="102" messageId="769f2e4f-56da-4865-988a-a9199c387a48"/>

I'm returning this as an XML via:

return simplexml_load_string($output);

$result is catching the return and it's coming back as:

$result = { 
  "@attributes" :  { 
    carrier : "102",
    messageId : "8d691cbe-d188-42b1-9041-387666d39c6a"
  }

How can I drill down to get the messageId as plane text? When I use this:

$result['messageId']

I get:

{ 
  "0" : "bf629ae9-c86a-486a-bfb0-704e16448ddf"
}

But I just want:

bf629ae9-c86a-486a-bfb0-704e16448ddf
Wil Wells
  • 205
  • 4
  • 14

1 Answers1

0

Figured it out in another post:

$msgID = (string) $result['messageId'];

You have to cast simpleXML Object to a string. POST: Get value from SimpleXMLElement Object

Community
  • 1
  • 1
Wil Wells
  • 205
  • 4
  • 14
  • You can also find a nice introduction to Simplexml in the PHP manual here: [Basic SimpleXML usage](https://php.net/manual/en/simplexml.examples-basic.php) – hakre Apr 01 '15 at 16:37