SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: RSS feed

  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    436
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    RSS feed

    PHP Code:
    $feed=file_get_contents('URL');
    $rss=new  SimpleXmlElement($feed);
    foreach(
    $rss->channel->item as $entry) {echo "<p><a href='$entry->link' title='$entry->title'>" $entry->title "</a></p>";} 
    who can tell me what the $rss->channel->item mean.
    in php,i found state a class's format is
    PHP Code:
    class classname{...;} 
    when refer the content of the class,the format is
    $variablename=new classname, $variablename->the content of the class,however,in the above example,i found there is now state channel in SimpleXmlElement($feed);why?
    i am a beginner of php and expect some can explain these details.

    thank you!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Location
    Austria
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A rss-feed consists of 1 to n "item"-xml-elements. Each item describes a news. A rss-feed is a collection of some news.

    For example a xml-structure of a rss-feed:
    Code:
    <?xml version="1.0"?>
    <rss version="2.0">
       <channel>
          ...
          <item>...</item>
          <item>...</item>
       </channel>
    </rss>
    SimpleXmlElement converts such a XML-string into a object-/array-structure.

    var_dump($rss->channel->item);
    Shows you all item-Elements.
    item is an object of channel, channel is an object of rss.


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
  •