How to get the first element of a SimpleXML object?

$xml is a SimpleXML object.

 print_r($xml->Title); 

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

How do I access the first item?

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

nothing displays!

+6
source share
1 answer

Try

 echo (string) $xml->Title; 

You must specify it as a string.

+12
source

Source: https://habr.com/ru/post/955821/


All Articles