Status
Not open for further replies.

Big D

Member
Hello,

I've been trying to figure out the basics of setting up a simple rss feed from, say, the BBC, on a .php page, but having gone through umpteen articles on the net I am going round in circles.

I cannot figure out what I am meant to be creating file-wise to upload to site - and where - and what actually goes in the particular page I want the feed to appear on.

If anyone can help me along the way with this one I'd be very grateful.

Big D.
 

Forbairt

Teaching / Designing / Developing
should add
Code:
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>
";
}

You may also want to download the rss feed to your site and refresh it on intervals of 5 minutes 10 minutes so that you don't end up hammering the bbc website

for example if you site gets hit once a minute ... that'd be 60 hits to the BBC ... if you site gets hit 10 times a minute .. it'd be 600 hits .. and so on ... so the bbc may not like you doing that

You'll also be required to link back to their site / articles and give your source in most cases
 

Big D

Member
MagpieRSS

Forbairt, thank you for your reply.

I've just posted a message in the General chat section to explain that I've had to learn on the hoof since I lost my webmaster of 10 years, so there are still gaping holes in my knowledge.

However, it looks as though Magpierss has already been placed on my site for a feed set up by my former webmaster.

I notice there are 4 rss files in the directory:

rss.php
rss_cache.inc
rss_fetch.inc
rss_parse.inc

and the rss.php file reads as follows:

<?php
require_once 'rss_fetch.inc';
$url = 'http://news.bbc.co.uk/rss/newsonline_uk_edition/northern_ireland/rss091.xml';
$rss = fetch_rss($url);
$id=0;
echo "Site: ", $rss->channel['title'], "<br>\n";
foreach ($rss->items as $item ) {
if($id=="5") {
echo "</td><td><p>\n";
}
if($id=="10") {
echo "</td><td><p>\n";
}
if($id=="15") {
break;
}
$id++;
$title = $item[title];
$url = $item[link];
$description = $item[description];
echo "<a href=$url>$title</a><br>$description</li><br>\n";
}
?>

What I can't figure out is what code I should put in the page on which I would like the feed to appear, i.e. how do I activate the feed on a given web page?
 

Forbairt

Teaching / Designing / Developing
create a new file just to test its all working "filename.php"

put all your code into it I've simplified it slightly ... I think this code was being included as part of another file.


Code:
<?php

require_once 'rss_fetch.inc';

$url = 'http://news.bbc.co.uk/rss/newsonline_uk_edition/northern_ireland/rss091.xml';
$rss = fetch_rss($url);

echo "Site: ", $rss->channel['title'], "<br>\n";

foreach ($rss->items as $item ) {

 $title = $item[title];
 $url   = $item[link];
 $description   = $item[description];
 echo "<a href=$url>$title</a><br>$description</li><br>\n";

}

?>

once you know this is working ...

anywhere you want this to appear you could just put the code
<?PHP include "filename.php"; ?>
 

Big D

Member
Well done!

Forbairt, thank you very much for that - I have it working!

Just a couple of quickies:

1. Can these feeds be styled with css?
2. Presumably the feed source can simply be changed by changing the URL?
 

Forbairt

Teaching / Designing / Developing
Forbairt, thank you very much for that - I have it working!

Just a couple of quickies:

1. Can these feeds be styled with css?
2. Presumably the feed source can simply be changed by changing the URL?

Code:
echo "<a href=$url>$title</a><br>$description</li><br>\n";

there you have your link urls so yes you just have to give them a class or put the whole thing in a container div ? ... for example

Code:
<div class="rssFeed">
...
...
</div>

then its just down to you to style the output



I'd almost recommend you remove the $url bit from your include file

then when ever you want to include a rss feed
Code:
<?PHP
$url = "http://www.myurlformyrssfeed.com/my.rss";
include "filename.php"
?>
 

Big D

Member
One very last question in meantime

Right, I've managed to get the thing going and have styled it a bit with css, but the feed is pretty long - what way - if any - is there of controlling the number of items in the feed?

Until I get familiar with what each piece of the code does and get more adept at rss feeds generally I will almost certainly require more help, but I have to say that I do really appreciate your helpfulness.

To show my good faith in the meantime would a link from my website Library Ireland: Irish History and Culture to your site be of any use?

Big D.
 

Forbairt

Teaching / Designing / Developing
Right, I've managed to get the thing going and have styled it a bit with css, but the feed is pretty long - what way - if any - is there of controlling the number of items in the feed?

Until I get familiar with what each piece of the code does and get more adept at rss feeds generally I will almost certainly require more help, but I have to say that I do really appreciate your helpfulness.

To show my good faith in the meantime would a link from my website Library Ireland: Irish History and Culture to your site be of any use?

Big D.

to control the number of items you could do something like this

Code:
[FONT=monospace]
[/FONT]$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, 5);
where 5 is ... the number of items...


A link wouldn't hurt but isn't necessary :)
 

Big D

Member
Number of items unaffected

Forbairt,

The array slice line hasn't affected the length of the feed - don't know whether I've done something wrong?--

Code:
<?php
require_once 'rss_fetch.inc';
$url = 'http://news.bbc.co.uk/rss/newsonline_uk_edition/northern_ireland/rss091.xml';
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, 5);
echo "Site: ", $rss->channel['title'], "<br>\n";
foreach ($rss->items as $item ) {
 $title = $item[title];
 $url   = $item[link];
 $description   = $item[description];
 echo "<a href=$url>$title</a><br>$description</li><br>\n";
}
?>

For what it might be worth I have set up a link to your site at the following url Free Irish Reference Works
 

Forbairt

Teaching / Designing / Developing
cheers for the link :)


Code:
<?php
require_once 'rss_fetch.inc';
$url = 'http://news.bbc.co.uk/rss/newsonline_uk_edition/northern_ireland/rss091.xml';
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, 5);
echo "Site: ", $rss->channel['title'], "<br>\n";
foreach ($items as $item ) {
$title = $item[title];
$url = $item[link];
$description = $item[description];
echo "<a href=$url>$title</a><br>$description</li><br>\n";
}
?>
What we did was chop the 5 entries out into an array called $items

As such we have to change our foreach statement

enjoy :)
 

ghost

New Member
Any explanation for this behavior

Any explanation for this behavior
the following feed is from RTE
RTE Sport News
the two I am curious about
1 St Vincent's 2-08 Tyrrellspass 0-07
2 O?Connor appointed to Kerins O?Rahillys post

Source code for no 2
<h1>O'Connor appointed to Kerins O'Rahillys post</h1>
question why in the second case was the apostrophe converted to ?
 

Big D

Member
No idea

I wish I could help on this one, but it is beyond me - the apostrophes seem to be working in some items but not in others -strange.

Hopefully someone with a bit more savvy can provide an answer
 

Forbairt

Teaching / Designing / Developing
can you post your php code ?


This ...
Code:
<?php
require_once 'rss_fetch.inc';

$url = 'http://www.rte.ie/rss/sport.xml';
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, 5);
echo "Site: ", $rss->channel['title'], "<br>\n";
foreach ($items as $item ) {
$title = $item[title];
$url = $item[link];
$description = $item[description];
echo "<a href=$url>$title</a><br>$description</li><br>\n";
}
?>
works fine for me ... everything displaying correctly
 

ghost

New Member
RSS Test

Used the code you posted for Big D
I just ran the code in my own server to test it.
I have used Last Rss on a few sites and I get a lot of this type of stuff the quotations in the Examiner site just made me drop it altogether.
I don't know if this is an encoding problem , as you can see here apostrophes are showing in some instances and not in others
just curious to know why.
 
Status
Not open for further replies.
Top