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?
将其转换为字符串:
$data_to_save['title'] = (string) $picasa_feed->title;
You want to invoke the SimpleXMLElement's magic __toString
method by casting it to string. Try: $data_to_save['title'] = (string)$picasa_feed->title;
这应该工作:
$data_to_save['title'] = (string) $picasa_feed->title;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.