Re: Parsing RSS

From: Date: Sun, 13 Aug 2006 02:37:13 +0000
Subject: Re: Parsing RSS
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-240591@lists.php.net to get a copy of this message
John Taylor-Johnston wrote:
Is there something already created to open an rss file, parse it, and include() the useful stuff into an html file? Not all my students have an rss reader. http://jtjohnston.ca/jtjohnston.rss
RSS is just XML. Use SimpleXML to map it to a PHP object and just print out whatever you want from it directly. eg. <?php $rss = simplexml_load_file('http://jtjohnston.ca/jtjohnston.rss'); $channel = $rss->channel; echo <<<EOB <img src="{$channel->image->url}" style="float: right;"/> <h1>{$channel->title}</h1> <h2>{$channel->description}</h2> EOB; foreach($channel->item as $item) { echo <<<EOB <h3><a href="{$item->link}">{$item->title}</a> ({$item->pubDate})</h3> {$item->description} <br clear="left" /> <hr /> EOB; } ?> Very ugly HTML markup there, of course, but add a bit of CSS and make it prettier. -Rasmus

« previous php.general (#240591) next »