<p>I get a URL from a user. I need to know:<br/>
a) is the URL a valid RSS feed?<br/>
b) if not is there a valid feed associated with that URL</p>
<p>using PHP/Javascript or something similar</p>
<p>(Ex. <a href="http://techcrunch.com" rel="nofollow noreferrer">http://techcrunch.com</a> fails a), but b) would return their RSS feed)</p>

[{'answer_id': 61537, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 3, 'selected': False, 'text': "<p>a) Retrieve it and try to parse it. If you can parse it, it's valid.</p>\n\n<p>b) Test if it's an HTML document (server sent <code>text/html</code>) MIME-type. If so, run it through an HTML parser and look for <code>&lt;link&gt;</code> elements with RSS feed relations.</p>\n"}, {'answer_id': 61538, 'author': 'ConroyP', 'author_id': 2287, 'author_profile': 'https://Stackoverflow.com/users/2287', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://feedvalidator.org/" rel="noreferrer">This link</a> will allow you to validate the link against the RSS/Atom specifications using the W3C specs, but does require you to manually enter the url.</p>\n\n<p>There are a number of ways to do this programmatically, depending on your choice of language - in PHP, parsing the file <a href="http://www.contentwithstyle.co.uk/Blog/132/" rel="noreferrer">as valid XML</a> is a good way to start, then compare it to the <a href="http://www.php.net/manual/en/domdocument.schemavalidate.php" rel="noreferrer">relevant DTD</a>.</p>\n\n<p>For b), if the link itself isn\'t a feed, you can parse it and look for a specified feed in the &lt;head&gt; section of the page, searching for a link whose type is "application/rss+xml", e.g:</p>\n\n<pre><code>&lt;link rel="alternate" title="RSS Feed" \n    href="http://www.example.com/rss-feed.xml" type="application/rss+xml" /&gt;\n</code></pre>\n\n<p>This type of link is the one used by most browsers to "auto-discover" feeds (causing the RSS icon to appear in your address bar)</p>\n'}, {'answer_id': 61539, 'author': 'Bobby Jack', 'author_id': 5058, 'author_profile': 'https://Stackoverflow.com/users/5058', 'pm_score': 2, 'selected': False, 'text': '<p>Are you doing this in a specific language, or do you just want details about the RSS specification?</p>\n\n<p>In general, look for the XML prolog:</p>\n\n<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;\n</code></pre>\n\n<p>followed by an &lt;rss&gt; element, but you might want to validate it as XML, fully validate it against a DTD, or verify that - for example, each URL referred to is valid, etc. More detail would help.</p>\n\n<p><strong>UPDATE</strong>: Ah - PHP. I\'ve found this library to be pretty useful: <a href="http://magpierss.sourceforge.net/" rel="nofollow noreferrer">MagpieRSS</a></p>\n'}, {'answer_id': 61546, 'author': 'Gilean', 'author_id': 6305, 'author_profile': 'https://Stackoverflow.com/users/6305', 'pm_score': 5, 'selected': True, 'text': '<p>Found something that I wanted:</p>\n\n<p>Google\'s <a href="http://code.google.com/apis/ajaxfeeds/" rel="noreferrer">AJAX Feed API</a> has a load feed and lookup feed function (Docs <a href="http://code.google.com/apis/ajaxfeeds/documentation/reference.html#_intro_fonje" rel="noreferrer">here</a>).</p>\n\n<p>a) <a href="http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&amp;q=http://www.digg.com/rss/index.xml" rel="noreferrer">Load feed</a> provides the feed (and feed status) in JSON</p>\n\n<p>b) <a href="http://ajax.googleapis.com/ajax/services/feed/lookup?v=1.0&amp;q=http://www.techcrunch.com" rel="noreferrer">Lookup feed</a> provides the RSS feed for a given URL</p>\n\n<p>Theres also a find feed function that searches for RSS feeds based on a keyword.</p>\n\n<p>Planning to use this with JQuery\'s $.getJSON</p>\n'}, {'answer_id': 62237, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>The <a href="http://framework.zend.com/manual/en/zend.feed.findFeeds.html" rel="nofollow noreferrer">Zend Feed class</a> of the <strong>Zend-framework</strong> can automatically parse a webpage and list the available feeds.</p>\n\n<p>Example: <br></p>\n\n<pre><code>$feedArray = Zend_Feed::findFeeds(\'http://www.example.com/news.html\');\n</code></pre>\n'}, {'answer_id': 71816, 'author': 'Corion', 'author_id': 11253, 'author_profile': 'https://Stackoverflow.com/users/11253', 'pm_score': 2, 'selected': False, 'text': '<p>For Perl, there is <a href="http://search.cpan.org/dist/Feed-Find/" rel="nofollow noreferrer">Feed::Find</a> , which does automate the discovery of syndication feeds from the webpage. The usage is quite simplicistic:</p>\n\n<pre><code>use Feed::Find;\nmy @feeds = Feed::Find-&gt;find(\'http://example.com/\');\n</code></pre>\n\n<p>It first tries the <code>link</code> tags and then scans the <code>a</code> tags for files named <code>.rss</code> and something like that.</p>\n'}]
['https://Stackoverflow.com/questions/61535', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6305/']