0

I am adding an RSS feed to my website. I created the RSS.xml index file and next I want to display its contents in a nicely formatted way in a webpage.

Using PHP, I can do this:

$index = file_get_contents ($path . 'RSS.xml');
echo $index;

But all that does is dump the contents as a long stream of text with the tags removed.

I know that treating RSS.xml as a link, like this:

<a href="../blogs/RSS.xml">
  <img src="../blogs/feed-icon-16.gif">Blog Index
</a>

causes my browser to parse and display it in a reasonable way when the user clicks on the link. However I want to embed it directly in the web page and not make the user go through another click.

What is the proper way to do what I want?

5
  • github.com/jewelhuq/Online-News-Grabber/tree/master/worldnews Follow this . hope you will get your answer. Commented Sep 23, 2015 at 22:51
  • Personally I might be tempted to use XSLT - either in javascript or php as it'll give you the ability to govern the aspects from the rss feed get displayed and how. Commented Sep 23, 2015 at 23:03
  • Use XSLT for what? Sorry for ignorance, I started today with RSS feeds. I need the rss XML file to be standard and recognized by aggregators. Commented Sep 23, 2015 at 23:09
  • @jewelhuq I was just looking through your code but am not finding where you load or parse an RSS xml file. Any hints? Commented Sep 23, 2015 at 23:17
  • check out : github.com/jewelhuq/Online-News-Grabber/blob/master/worldnews/… page specially getData function. Commented Sep 23, 2015 at 23:54

2 Answers 2

1

Use the following code:

 include_once('Simple/autoloader.php');
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->enable_cache(false);
    $feed->set_output_encoding('utf-8');
    $feed->init();

     $i=0;
    $items = $feed->get_items();
    foreach ($items as $item) {
    $i++;
   /*You are getting title,description,date of your rss by the following code*/
    $title = $item->get_title();
    $url   = $item->get_permalink();
    $desc  = $item->get_description();
    $date  = $item->get_date();
    }

Download the Simple folder data from : https://github.com/jewelhuq/Online-News-Grabber/tree/master/worldnews/Simple

Hope it will work for you. There $url mean your rss feed url. If you works then response.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I gave you a +1 but it doesn't quite answer the question. I discovered a solution while you were doing your post and have a created a separate answer.
0

Turns out, it's simple by using the PHP xml parer function:

$xml = simplexml_load_file ($path . 'RSS.xml');
$channel = $xml->channel;
$channel_title = $channel->title;
$channel_description = $channel->description;

echo "<h1>$channel_title</h1>";
echo "<h2>$channel_description</h2>";

foreach ($channel->item as $item)
{
  $title = $item->title;
  $link = $item->link;
  $descr = $item->description;

  echo "<h3><a href='$link'>$title</a></h3>";
  echo "<p>$descr</p>";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.