Find RSS / Atom feed on a web page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ed209
Forum Contributor
Posts: 153
Joined: Thu May 12, 2005 5:06 am
Location: UK

Find RSS / Atom feed on a web page

Post by ed209 »

I'm building some functionality that will enable users to import their existing blog posts to their account on my site. I have already implemented this and it works great as long as the user submits an RSS feed URL to my site. The problem I'm having is that many users just paste in their blog URL rather than their RSS feed url. I could resort to forcing users to go and get their RSS url by validating the address they submit but, well, I'm just too nice and I'd love to be able to get that feed URL for them.

Is there anything that will find an RSS feed on a web page? I noticed that Firefox does it with a little icon on in the address bar.
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Re: Find RSS / Atom feed on a web page

Post by R4000 »

Firefox does this by looking for the following in the page's <head>:

Code: Select all

<link href="http://www.example.com/some.rss" rel="alternate" type="application/rss+xml" title="TITLE OF YOUR RSS FEED" />
It depends how detailed you want to do this.
You could detect all <a> links for one with .xml in it and then visit that link and see if its a vaild rss feed.
Or you could visit every link on the page to detect for a rss feed.
Or you could just try to detect the code above for a rss feed (using regexp?)
Post Reply