SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Parse rss

  1. #1
    SitePoint Enthusiast edgarzakaryan's Avatar
    Join Date
    Aug 2012
    Location
    Yerevan, Armenia
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse rss

    Hi everyone!

    I'm parsing wordpress rss, and I'm getting this
    Code:
    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
                    (
                        [url] => 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.

  2. #2
    SitePoint Enthusiast edgarzakaryan's Avatar
    Join Date
    Aug 2012
    Location
    Yerevan, Armenia
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have found the solution.

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

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

  3. #3
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Attributes are accessible via the attributes() method, or array-style syntax. Examples would look like:


    $obj->enclosure->attributes()->url
    $obj->enclosure['url']

    See Basic SimpleXML Usage in the manual.
    Salathe
    Software Developer and PHP Manual Author.

  4. #4
    SitePoint Enthusiast edgarzakaryan's Avatar
    Join Date
    Aug 2012
    Location
    Yerevan, Armenia
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    Attributes are accessible via the attributes() method, or array-style syntax. Examples would look like:


    $obj->enclosure->attributes()->url
    $obj->enclosure['url']

    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.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •