Validating an RSS Feed with PHP

I have a project I’m working on that a user can submit an RSS Feed with his blog submission.

I need to check this RSS Feed and make sure it’s valid before I let the submission go through. How do I do this??

I found this class, but it doesn’t work for me at all:
http://www.phpclasses.org/browse/package/2976.html

I also found this, but the reply is vague and doesn’t help me:

Any help would be GREATLY appreciated!!

simplexml_load_string returns false on errors, maybe that will do the trick.

Personally, I would validate the RSS using an external resource / service / API.

Say for example, we had this feed from Ebay:-

http://www.ebay.co.uk/rss/somefeed.xml

I would use cURL to obtain the page generated from this URL

http://feedvalidator.org/check.cgi?url=http://www.ebay.co.uk/rss/somefeed.xml

If within that source we had the string “This is a valid RSS feed” , Bingo!

Just some random thinking and putting it out there.

That’s what my first example used, but it didn’t work… do you know of any sample code that would help me out?

I appreciate the quick responses!

Sure.


<?php

function validateFeed( $sFeedURL )
{

    $sValidator = 'http://feedvalidator.org/check.cgi?url=';
    
    if( $sValidationResponse = @file_get_contents($sValidator . urlencode($sFeedURL)) )
    {
        if( stristr( $sValidationResponse , 'This is a valid RSS feed' ) !== false )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}

?>

Happy hunting!

SilverB.

Thanks very much!