Jump to content

[SOLVED] How to include XML Feeds on your site


mazman13

Recommended Posts

I'm trying to find a pretty quick way to incorp XML feeds to your site.

 

I had a HUGE code that I used on my old server, but I now moved to a new GoDaddy server and the code no longer works. So i'm trying to find something that will work. I host podcasts, so XML feeds are pretty important.

 

Thanks guys

Yeah, and I'm just not having any luck finding anything that will work.

 

The one thing I did find was that one huge PHP code that would read files, but its not working on the new server. Plus there has to be an easier way.

 

I've used sites that can do it for you, i.e.(feedroll.com), but they charge now. And its a pain to go through them when you can (at least try) do it yourself.

 

Thanks guys

Hey man-

 

I installed the program on my host, but for some reason its returning "object"...anything i'm doing wrong?

 

<?php require_once('magpierss/rss_fetch.inc'); ?>

<strong><font size="3">Download ANY of your favorite past shows here! But hurry,

who knows how long they will be available?</font></strong><br /><br />

<?php

$url = "http://www.michaelzavala.com/feed.xml";

$rss = fetch_rss($url);

echo"$rss";

?>

<br>

</p>

Take a look at this example from the Magpie homepage. When you call fetch_rss(), it returns an object that you then need to pull apart to display what you want out of it:

<?php
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>
";
foreach ($rss->items as $item ) {
$title = $item[title];
$url   = $item[link];
echo "<a href=$url>$title</a></li><br>
";
}
?>

 

Notice that the variable "$rss->items" holds an array of the feed items, so you can loop through that array and display those items as you see fit on your page.

If I wanted to get only the 1st 3 on that XML file...how would I limit that? I couldn't do it with a foreach right?

 

You could, but you'd be better off with a for loop:

<?php
$limit = 3;
for ($i = 0; $i < $limit; $i++) {
  $line = $rss->items[$i];
  // Display $line
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.