I want to display RSS feeds of a website on my website. This could be easily done by online services like: www.rssinclude.com, www.feedgrabbr.com, etc. But I want the full code... right from the beginning.
Asked
Active
Viewed 4,710 times
-6
-
what code.... I want to display RSS feeds ... For example that of Telegraph.co.uk – Edi Golfgon Jul 02 '15 at 10:36
-
Well it wont display itself – Jul 02 '15 at 10:37
-
that's why I'm asking, how to display it... – Edi Golfgon Jul 02 '15 at 10:40
-
5You seem to be confused this is not the code restaurant where you order it and we write it – Jul 02 '15 at 10:42
-
@EdiGolfgon : Calling someone as "Dumbhead", who is trying to help you is not fair. [post has been removed]. Respect everyone in SO irrespective you whether the person gave correct answer or not. Atleast that person spent time for you to answer your query. – Makesh Jul 02 '15 at 10:55
2 Answers
2
For my soccer news website, I use the following code: (Hope, it works)
<?php
class rss
{
var $feed;
function rss($feed)
{
$this->feed = $feed;
}
function parse()
{
$rss = simplexml_load_file($this->feed);
$rss_split = array();
foreach ($rss->channel->item as $item) {
$title = (string) $item->title;
$link = (string) $item->link;
$description = (string) $item->description;
$rss_split[] = '<div>
<a href="'.$link.'" target="_blank" title="">'.$title.'</a>
<hr>
</div>';
}
return $rss_split;
}
function display($numrows,$head)
{
$rss_split = $this->parse();
$i = 0;
$rss_data = '<div class="container">
<div class="title">'.$head.'</div>
<div class="links">';
while ( $i < $numrows )
{
$rss_data .= $rss_split[$i];
$i++;
}
$trim = str_replace('', '',$this->feed);
$user = str_replace('&lang=en-us&format=rss_200','',$trim);
$rss_data.='</div></div>';
return $rss_data;
}
}
$feedlist = new rss("http://www.fifa.com/rss/index.xml");
echo $feedlist->display(10,"FIFA");
?>

Sergio Tulentsev
- 226,338
- 43
- 373
- 367

N3R4ZZuRR0
- 2,400
- 4
- 18
- 32
-
1Yeah, it's weird, backticks should have worked here. Anyhow, indenting each line with 4 spaces is better. – Sergio Tulentsev Jul 02 '15 at 13:40
-
1
Try Simple XML
<?php
$html = "";
$url = "file.rss";
$xml = simplexml_load_file($url);
for($i = 0; $i < 10; $i++){
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
$description = $xml->channel->item[$i]->description;
$pubDate = $xml->channel->item[$i]->pubDate;
$html .= "<a href='$link'><h3>$title</h3></a>";
$html .= "$description";
$html .= "<br />$pubDate<hr />";
}
echo $html;
?>

Makesh
- 1,236
- 1
- 11
- 25