note 92904 deleted from book.simplexml by danbrown

From: Date: Thu, 13 Aug 2009 18:50:02 +0000
Subject: note 92904 deleted from book.simplexml by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159459@lists.php.net to get a copy of this message
Note Submitter: dan at danbeam dot org ---- 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).

« previous php.notes (#159459) next »