1

I have this:

$xml = simplexml_load_file('test.xml');
print"<pre>";
print_r($xml);

It printout this:

SimpleXMLElement Object
(
    [b] => SimpleXMLElement Object
        (
            [c] => SimpleXMLElement Object
                (
                    [d] => 543
                )

        )

)

but when I type echo $xml["b"]["c"]["d"]; nothing happens

1
  • if you are using PHP5, I suggest you use OO approach of SimpleXML Commented Aug 11, 2011 at 9:06

2 Answers 2

4

the print_r is kind of misleading,
actually the $xml is series/array of SimpleXmlElement objects

so

echo (int)$xml->b->c->d;  --- type casting is required

here is some reference you should take a look first

Additional to type casting,
because everything node inside the xml object is either string or int

PHP will auto convert for numeric string to integer,
however, is clearer if you provide the type hinting

var_dump($xml); --- you should see more information on the data type
Sign up to request clarification or add additional context in comments.

Comments

0

Try echo $xml->b->c->d;

$xml is not array they are objects.

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.