Jump to content

how to check if link is valid? regex maybe?


pouncer

Recommended Posts

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 ?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.