14

$xml is a SimpleXML object.

print_r($xml->Title); 

outputs SimpleXMLElement Object ( [0] => K&H 3093 Extreme Weather Kitty Pad with Fleece Cover )

How do I access the first element?

print_r($xml->Title[0]); 

outputs nothing!

3
  • That returns: SimpleXMLElement Object ( ) Commented Oct 12, 2013 at 0:27
  • 6
    Cast to string ? (string) $xml->Title Commented Oct 12, 2013 at 0:38
  • SimpleXMLElement does not require var_dump or print_r to understand it, but reading the manual: Basic SimpleXML usage because it's so simple that it's so magic, that print_r and var_dump don't show you the picture unless you've fully understood how print_r and var_dump work (or better say: not work) with SimpleXMLElement. Commented Sep 28, 2014 at 10:50

1 Answer 1

30

Try

echo (string) $xml->Title; 

You have to cast it as a string.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.