Click to See Complete Forum and Search --> : PHP RSS management; simple question


King Zarathu
January 18th, 2008, 11:00 PM
I need to know how to determine whether or not a supplied URL leads to a valid RSS XML page.

Example

is_valid("http://www.google.com"); -> FALSE

is_valid("http://digg.com/rss/index.xml"); -> TRUE

PeejAvery
January 19th, 2008, 11:00 AM
One clarification is necessary. Are you trying to check for a valid XML file, or just to make sure that it is in XML format, or that it has the XML extension?

The first would be best to send the data to W3C's validator (http://www.w3.org/2001/03/webdata/xsv) and parse the results.

The second would would greatly depend on what tags were required. You would use regular expressions for the search for < and >. Solving the last would be the simplest.

function is_valid($filename){
$ext = strtolower(substr(strrchr($filename, '.'), 1));
return ($ext == 'xml') ? true : false;
}