问题
I have an object called $picasa_feed like this:
SimpleXMLElement Object
(
[guid] => https://picasaweb.google.com/data/entry/base/user/0000000000000000/albumid/0000000000000000?alt=rss&hl=en_US
[pubDate] => Fri, 12 Dec 2008 20:00:00 +0000
[category] => http://schemas.google.com/photos/2007#album
[title] => My Pictures
[description] => ...
[link] => https://picasaweb.google.com/0000000000000000/MyAlbum
[author] => Me
)
I want to take put a property value into an element of an associative array:
$data_to_save['title'] = $picasa_feed->title;
When I do that the value of $data_to_save is
Array
(
[title] => SimpleXMLElement Object
(
[0] => My Pictures
)
}
What I want is
Array
(
[title] => My Pictures
}
What am I doing wrong and how do I fix it?
回答1:
You want to invoke the SimpleXMLElement's magic __toString
method by casting it to string. Try: $data_to_save['title'] = (string)$picasa_feed->title;
回答2:
Cast it to string:
$data_to_save['title'] = (string) $picasa_feed->title;
回答3:
This should work:
$data_to_save['title'] = (string) $picasa_feed->title;
来源:https://stackoverflow.com/questions/14862977/access-simplexml-node-value-as-string