Jump to content

Recommended Posts

Hi guys I searched for this.

 

 

How to write a function that would return the RSS feed url (or list of URLs) for the given site ? I guess this comes down to loading the page and parsing it for 'link' tags with rel='alternate' attribute?

 

For example feeds for phpfreaks.comare hidden in here.

<link href="http://feeds.feedburner.com/phpfreaks" rel="alternate" type="application/atom+xml" title="Latest Content" />
<link href="http://feeds.feedburner.com/phpfreaks/tutorials" rel="alternate" type="application/atom+xml" title="Latest Tutorials" />
<link href="http://feeds.feedburner.com/phpfreaks/blog" rel="alternate" type="application/atom+xml" title="Latest Blog Posts" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

 

Can someone provide me with the code?

 

 

Link to comment
https://forums.phpfreaks.com/topic/131838-discover-rss-feed-from-an-url/
Share on other sites

acctually youd be better off searching for the application/atom+xml meta type, but yes you are on the right track:

 

@s vicodin said we wont right it for you. but remember alot of servers wont allow you to include external pages.

  • 2 weeks later...

My ways are not the best, but they work and since I hate regex this is how I would do it.

 

<?php

function grabRSSFeeds($website) {
    $file = file($website);

    foreach ($file as $line) {
        $line = strtolower($line);
        if (stristr($line, "link") !== false) {
             if (stristr($line, "application/rss+xml") !== false) {
				$line = str_replace("\"", "", $line);
				$line = str_replace("'", "", $line);
                    $splitIt = split("href=", $line);
				$linked = split(" ", $splitIt[1]); // split at first space
				$links[] = $linked[0];
             }
        }elseif (stristr($line, "<body")) {
            break; //kill the foreach if we reached the body tag.
        }
    }
   
    return $links;
}

echo '<pre>';
print_r(grabRSSFeeds('http://www.9news.com')); // should return an array of the links
echo '</pre>'
?>

 

Untested but should work.

 

EDIT: Added a ' and space check that "should" cover about any type of setup you would find.

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.