以字符串形式访问SimpleXML节点值

2022-04-13 00:00:00 php simplexml

我有一个名为$Picasa_Feed的对象,如下所示:

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
)

我希望将属性值放入关联数组的元素中:

$data_to_save['title'] = $picasa_feed->title;

执行此操作时,$DATA_TO_SAVE的值为

Array
(
    [title] => SimpleXMLElement Object
        (
            [0] => My Pictures
        )
}

我想要的是

Array
(
    [title] => My Pictures
}

我做错了什么,我如何修复它?


解决方案

您希望通过将其转换为字符串来调用SimpleXMLElement的魔力__toString方法。尝试:$data_to_save['title'] = (string)$picasa_feed->title;

相关文章