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!

George Brighton
  • 5,131
  • 9
  • 27
  • 36
Edward Yu
  • 776
  • 2
  • 6
  • 15
  • That returns: SimpleXMLElement Object ( ) – Edward Yu Oct 12 '13 at 00:27
  • 6
    Cast to string ? `(string) $xml->Title` –  Oct 12 '13 at 00:38
  • SimpleXMLElement does not require `var_dump` or `print_r` to understand it, but reading the manual: [Basic SimpleXML usage](http://php.net/manual/en/simplexml.examples-basic.php) 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**. – hakre Sep 28 '14 at 10:50

1 Answers1

29

Try

echo (string) $xml->Title;

You have to cast it as a string.

Galen
  • 29,976
  • 9
  • 71
  • 89