-5

I have XML string $input which is received from SOAP service

$xml = new SimpleXMLElement($input);
echo var_dump($xml). "<br />";

gives output:

object(SimpleXMLElement)#3 (2) {
  ["result"]=>
  string(5) "False"
  ["error"]=>
  string(13) "Login Failure"

How to get 'False' value or any in its place into an variable?

waghso
  • 623
  • 7
  • 23
  • Do you mean ```$xml["result"]```? – Snicksie May 05 '15 at 06:17
  • 2
    this is PHP OOP 101. How to access an object property – Rizier123 May 05 '15 at 06:18
  • 5
    @Snicksie `$xml["result"]` -> this will throw an error of type E_ERROR, because you can't access an object like an array :) – Florian May 05 '15 at 06:22
  • 1
    Thanks for all negative votes. I'm new in PHP. Can't figured how to do it. that's why I asked. – waghso May 05 '15 at 06:25
  • 1
    Just a tip: Use google with keywords from your output: php, object, access or something else, it's really easy to find with your favorite search engine :) – Florian May 05 '15 at 06:27
  • 2
    @Florian I clearly should learn to look closer, I didn't see the "Object", but automatically assumed an array. Too early in the morning :) – Snicksie May 05 '15 at 06:34

2 Answers2

4

Just use:

$yourvar = $xml->result;

To get "False" (or the value of result in your Xml).

Florian
  • 2,796
  • 1
  • 15
  • 25
0

To get the value of result from

 object(SimpleXMLElement)#3 (2) {
  ["result"]=>
  string(5) "False"
  ["error"]=>
  string(13) "Login Failure"

you can use:

$xmlObject = new SimpleXMLElement($input);
echo $xmlObject->result;

Output:

False

Learn more about SimpleXML with this example

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268