0

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?

0

3 Answers 3

1

Cast it to string:

$data_to_save['title'] = (string) $picasa_feed->title;
Sign up to request clarification or add additional context in comments.

Comments

0

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 Comments

Thanks to both of you. That did it! Is it always necessary to access object properties that way, or is it something particular to SimpleXMLElement?
Accessing the property of an object will yield whatever data type that property has. Due to the nested nature of XML, the SimpleXMLElement is just a collection of more SimpleXMLElements (nodes / children / [..]).
0

This should work:

$data_to_save['title'] = (string) $picasa_feed->title;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.