GET the RSS feed

Discussion in 'PHP' started by runeveryday, Jul 24, 2009.

  1. #1
    
    $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>";
    
    } 
    
    PHP:
    I used a blog's rss feed address instead of the url in $feed,but it didn't work.
    why?
    i learn php recently,can anyone give me the meanings of the $rss->channel->item .thank you!
    PS:my php environment supports the file_get_contents()function.
     
    runeveryday, Jul 24, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    check your rss feed address
     
    javaongsan, Jul 24, 2009 IP
  3. zandigo

    zandigo Greenhorn

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    $rss->channel->item relates to Class and Object. Read the manual for Classes and Object in php as php is Object-oriented programming language.

    If you are totally new to php and haven't learned any programming language before, don't bother this stuff right now. It just gives you headache :D.
     
    zandigo, Jul 24, 2009 IP
  4. runeveryday

    runeveryday Active Member

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    first,thank you for yours answers.i have read the php's Class and Object.too disappointed and puzzled.now,i know that states a class,the format is
    and when refer a variable from a class,the format is $variablename=new classname, $variablename->variablename,
    from these,i found there is no channel in SimpleXmlElement. why ,who can explain these for me.
    3Q!
     
    runeveryday, Jul 25, 2009 IP
  5. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If this is not working

    $feed=file_get_contents('URL');

    Please try getting the contents using curl and parse the output using the SimpleXMLElement

    Thanks!!
     
    HivelocityDD, Jul 25, 2009 IP
  6. imnarin

    imnarin Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I use magpierss very easy to read feed.
     
    imnarin, Jul 25, 2009 IP
  7. runeveryday

    runeveryday Active Member

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    what is curl ,can you explain it ?and tell me how it get the rss feed?
    thank u!
     
    runeveryday, Jul 25, 2009 IP
  8. imnarin

    imnarin Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    magpierss.sourceforge.net

    require_once 'rss_fetch.inc';
    
    $url = 'http://magpie.sf.net/samples/imc.1-0.rdf';
    $rss = fetch_rss($url);
    
    echo "Site: ", $rss->channel['title'], "<br>
    ";
    foreach ($rss->items as $item ) {
    	$title = $item[title];
    	$url   = $item[link];
    	echo "<a href=$url>$title</a></li><br>
    ";
    }
    
    Code (markup):
     
    imnarin, Jul 26, 2009 IP