note 92903 deleted from book.simplexml by danbrown
| From: | danbrown@php.net | Date: | Thu, 13 Aug 2009 18:50:01 +0000 |
| Subject: | note 92903 deleted from book.simplexml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159458@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Correcting/adding to charlie at blankcanvasstudios dot com's code:
function is_rss($feedxml) {
$feed = @simplexml_load_string($feedxml);
return($feed->channel->item &&
stripos($feedxml,'<rss')!==false)?true:false;
}
function is_atom($feedxml) {
$feed = @simplexml_load_string($feedxml);
$ns = implode('',$feed->getNamespaces());
return($feed->entry && strpos($ns,'Atom')!==false)?true:false;
}
The original function simply checked that the input follows the same general XML structure as
RSS/Atom, but not much beyond that. To do a *slightly* deeper check I propose a namespace check on
the feed (for Atom) and a verification that there's an <rss> tag (for RSS).