πŸ“• Node [[2004 01 18 using php to integrate rss feeds into your website]]
πŸ“„ 2004-01-18-using-php-to-integrate-rss-feeds-into-your-website.md by @bmann


layout: post title: Using PHP to integrate RSS feeds into your website created: 1074470820 categories: - RSS - MagpieRSS - PHP


PHP can be used to easily include feeds from other sites. The main advantage over a JavaScript solution is that everything can be run from your own site and you can take advantage of caching. The PHP can output straight HTML, which is fully searchable by search engines. As well, since all the files are "local" (except for updates to the included feeds), display tends to be faster, not relying on a JavaScript call to an external site for every page view.
I&#39;ve chosen to use <a href="http://magpierss.sourceforge.net/">MagpieRSS</a> for my example, mainly because it is very, very easy to use while at the same time being quite feature rich. It is of course GPL, so you can use and extend it to your heart&#39;s content.

It should work &quot;out of the box&quot;. Download the <code>magpierss</code> archive to your server space and decompress it. Now, go to the <code>magpie_simple.php</code> file (which should be at <code>http://www.example.com/magpierss-0.5.2/scripts/magpie_simple.php</code>) and enter in the URL of a feed. Ta-da! You&#39;ve got a feed displayed.

You&#39;ll want to add all the settings and includes in one file, so that your feed can easily be included in any page by just using a simple line or two of PHP. From the Magpie site, here is a really simple example of all the code you need:
require_once 'rss_fetch.inc';

$url = 'http://magpie.sf.net/samples/imc.1-0.rdf';
$rss = fetch_rss($url);

echo "Site: ", $rss->channel['title'], "<br>\n";
foreach ($rss->items as $item ) {
	$title = $item[title];
	$url   = $item[link];
	echo "<a href=$url>$title</a></li><br>\n";
}
For the complete example, including the walk-through of uploading files and setting permissions, see the specific example for OpenSourceXperts.com.

Loading pushes...

Rendering context...