Parse rss

Hi everyone!

I’m parsing wordpress rss, and I’m getting this


SimpleXMLElement Object
(
    [title] => Hello world!
    [link] => http://blog.example.com/?p=1
    [comments] => http://blog.example.com/?p=1#comments
    [pubDate] => Fri, 10 Aug 2012 13:41:54 +0000
    [category] => SimpleXMLElement Object
        (
        )

    [guid] => http://blog.example.com/?p=1
    [description] => SimpleXMLElement Object
        (
        )

    [enclosure] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                     => http://blog.example.com/wp-content/uploads/2012/08/Winter-150x150.jpg
                    [length] => 9698
                    [type] => image/jpg
                )

        )

)

I can then get all datas from this object, but I cant get @attributes. How can I access to url?

For example to access title, I can write $rss->title, but I cant write $rss->enclosure->@attributes->url to get it.
What can I do in this case?

Thanks.

I have found the solution.

If we need to get url from attributes, we should write like this.

$obj->enclosure->attributes()->url.

Attributes are accessible via the attributes() method, or array-style syntax. Examples would look like:

$obj->enclosure->[COLOR="#006400"]attributes()->url[/COLOR] $obj->enclosure[COLOR="#006400"]['url'][/COLOR]

See Basic SimpleXML Usage in the manual.

Thanks Salathe, I think it will be more easy to use array, because I’m using smarty, I will change my script.