AudiS2 Posted November 7, 2008 Share Posted November 7, 2008 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? Quote Link to comment Share on other sites More sharing options...
vicodin Posted November 8, 2008 Share Posted November 8, 2008 This isn't the right place if your looking for someone to write it for you. Try it on your own and if your having an issue we can then help you find your issue. Quote Link to comment Share on other sites More sharing options...
blueman378 Posted November 8, 2008 Share Posted November 8, 2008 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. Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 Try looking at cUrl extension. Quote Link to comment Share on other sites More sharing options...
AudiS2 Posted November 9, 2008 Author Share Posted November 9, 2008 OK lets start preg_match('/\<link rel="alternate" type="application\/rss\+xml" title="(.*?)" href="(.*?)"/', $html, $matches); should fill the title and the link, but what if tags are in different order? Quote Link to comment Share on other sites More sharing options...
AudiS2 Posted November 17, 2008 Author Share Posted November 17, 2008 Anyone? Quote Link to comment Share on other sites More sharing options...
premiso Posted November 17, 2008 Share Posted November 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.