2

have a question regarding obtaining a value from a simpleXML Object. So firstly, I do this

$data = $xml->children('SOAP-ENV', true)->Body->children()->ExecuteQueryResponse->pdomOutput->recipient->attributes()->email;
var_dump($data);

And that returns the following

object(SimpleXMLElement)#8 (1) {
  [0]=>
  string(26) "[email protected]"
}

I need just the email address from this. So I then proceed to do this

$this->response = (string)$data[0];
var_dump($this->response);

Now I would expect the above to return just the email address, but instead, it returns everything, including the type e.g.

string(26) "[email protected]"

I can easily get the email address from this using something like preg_match, but surely this is not the way to go? Is it not possible to get the value without the type?

Thanks

3
  • 1
    What do you mean type? Did you try and use echo instead of var_dump? Commented Nov 2, 2015 at 13:50
  • I was actually returning the whole value, and it didnt like me doing that without echoing it out (because of ajax). Seems to work now thanks Commented Nov 2, 2015 at 13:57
  • var_dump is doing what it's suppose to do, it's showing you the type and length and the content of the variable. While echo "just" shows the content. Commented Nov 2, 2015 at 14:00

1 Answer 1

2

If you just want to have the string, SimpleXML has the __toString() function for SimpleXMLElements. So with your code this would be:

$data = $xml->children('SOAP-ENV', true)->Body->children()->ExecuteQueryResponse->pdomOutput->recipient->attributes()->email;
$this->response = $data[0]->__toString();
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.