Before I dive into writing a validator to check if a URL is actually pointing to an RSS feed, I did a bit of searching for some validators that may exist out there but had little luck with any reliable ones.
I just wanted to ask the community if any of you know of an RSS validator by URL?
If I were to write my own, what do you suggest?
I was thinking of just checking for the first instance of a line of text and making sure it defines <?xml version="1.0" encoding="UTF-8"?>
and then perhaps checking that the next item is an <rss>
node.
What are your thoughts here? Could there ever be a case where a feed may not follow the syntax stated above?
Also note, one method I attempted to use was the following:
$valid = true;
try{
$content = file_get_contents($feed);
if (!simplexml_load_string($content)){
$valid = false;
}
} catch (Exception $e){
$valid = false;
}
Unfortunately it seems that I cannot suppress warnings (error_reporting(0)
is not working..) so the just spams me with warnings.
SOLUTION
For anyone that is interested, I used the W3C Validator API
$url = "http://feed_url.com";
$validator = "http://validator.w3.org/feed/check.cgi";
$validator .= "?url=".$url;
$validator .= "&output=soap12";
$response = file_get_contents($validator);
$a = strpos($response, '<m:validity>', 0)+12;
$b = strpos($response, '</m:validity>', $a);
$result = substr($response, $a, $b-$a);
echo $result;
This will return true or false accordingly.