Re: Parsing RSS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux