Jump to content

rss feed problem


pouncer

Recommended Posts

view_rss.php

 

<?

$rss_url = "http://www.php.net/news.rss";
    if (!$rss_data = @file_get_contents($rss_url)) {
        echo "<p>No RSS found at $rss_url</p><p>Hmmm thats not meant to happen. RSS Fail!</p>";
    } else {

    $rss_xml = SimpleXML_Load_String($rss_data);

    $channel_title = $rss_xml->channel->title;
    $channel_link = $rss_xml->channel->link;

    foreach ($rss_xml->channel->item as $item) {
        $item_title = $item->title;
        $item_link = $item->link;
        $item_description = $item->description;
        echo "<h3><a href=\"$item_link\">$item_title</a></h3><p>$item_description</p><p class=\"text_right\"><a href=\"$item_link\">Continue reading  $item_title</a></p>\n";
        }
    }
?>

 

Doesn't seem to display nothing for me. but when i try another rss link like

 

$rss_url = "http://www.shanedj.com/blog/feed/rss/";

 

 

then it works fine, any ideas whats going wrong guys?

Link to comment
https://forums.phpfreaks.com/topic/152988-rss-feed-problem/
Share on other sites

The http://www.shanedj.com/blog/feed/rss/  is working as you expect it...

<channel>
<item>blah</item>
<item>blah</item>
<item>blah</item>
<item>blah</item>
</channel>

while http://www.php.net/news.rss is looking like this:

<channel>
<stuff>de blah</stuff>
<stuff>de blah</stuff>
<stuff>de blah</stuff>
<items>with an s</items>
</channel>
<item>Looking for this?</item>
<item>blah</item>
<item>blah</item>

item is not a child of channel in the php freaks rss.

Try:

<?php

$rss_url = "http://www.php.net/news.rss";
    if (!$rss_data = @file_get_contents($rss_url)) {
        echo "<p>No RSS found at $rss_url</p><p>Hmmm thats not meant to happen. RSS Fail!</p>";
    } else {

    $rss_xml = SimpleXML_Load_String($rss_data);

    $channel_title = $rss_xml->channel->title;
    $channel_link = $rss_xml->channel->link;

    foreach ($rss_xml->item as $item) {
        $item_title = $item->title;
        $item_link = $item->link;
        $item_description = $item->description;
        echo "<h3><a href=\"$item_link\">$item_title</a></h3><p>$item_description</p><p class=\"text_right\"><a href=\"$item_link\">Continue reading  $item_title</a></p>\n";
        }
    }
?>

Link to comment
https://forums.phpfreaks.com/topic/152988-rss-feed-problem/#findComment-803598
Share on other sites

I've attached a file that may be of some help to you. Its custom code based on a few snippets I've found around. It will open almost any page but really only effectively handles RSS/XML.

It uses the Header tags and indents for importance / tree.

 

EDIT: Made quick change to file

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/152988-rss-feed-problem/#findComment-804012
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.