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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.