pouncer Posted April 6, 2009 Share Posted April 6, 2009 function isValidRSSLink($link) { //return true if the link is a valid rss feed link like // www.php.net/news.rss } can someone help me with a function to check if the link is a valid url to a rss feed page? i think all rss feeds end in .xml or .rss ? Quote Link to comment Share on other sites More sharing options...
corbin Posted April 6, 2009 Share Posted April 6, 2009 $ext = substr($str, -4, 4); if($ext == '.xml' || $ext == '.rss') Would be the simplest way. Quote Link to comment Share on other sites More sharing options...
Axeia Posted April 6, 2009 Share Posted April 6, 2009 Not all the rss and xml feeds end on those extensions. You could easily create an index.php sending out an rss or xml header and rss/xml. Then the name would be something not ending in any extension or .php. (Can come up with other exceptions as well, but you're not likely to come across those situations). Based on the url itself you wont be able to tell, you'll need to visit the page with php itself and either check the headers, or it's content. Which might not be possible depending on your host. Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2009 Author Share Posted April 6, 2009 Ok can someone then tell me a regex to check if the link is actually an appropriate web link then? Quote Link to comment Share on other sites More sharing options...
Axeia Posted April 7, 2009 Share Posted April 7, 2009 Like I said, you can't rely on the format of the URL to determine if something is an RSS feed or not. A regular expression would do you no good, unless you're using it on the loading the page trough say.. curl and then applying it on the content or response header. Before we get into that however you may want to check if your host even supports it and if it does if it's without limits. The (free) host I use for example states in the EULA that I can only use curl once every hour. To see if it's supported simply use a phpinfo file and ctrl+f for curl. <?php phpinfo(); ?> If it's not supported you'll just have to 'believe' the user, perhaps post some link to an explanation of what RSS and XML look like. Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 7, 2009 Author Share Posted April 7, 2009 yes i checked that. curl is supported. could you give me that regex? 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.