Welcome to WebmasterWorld Guest from

Forum Moderators: bill & werty

Message Too Old, No Replies

Placing a RSS feed on my site

Things to do



6:35 pm on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


After a lot of thinking on what to have on my homepage, I have now decided on having a RSS feed from Google News besides a few articles, etc.

When I checked out Google feed, it is inside <rss>..</rss> tags. I would like to know how I can include them in my HTML page.

Also, should I enter the code inside a table so that it remains where I want it to be or is there some other procedure.



4:10 am on Jan 24, 2006 (gmt 0)

5+ Year Member

I have used rss feeds extensively on my sites and they are great. I have not used Google News in favour of other providers and news relevant to my sites.

I build all my sites in php and so process the xml feed with php to produce the html that is viewed on the page. If you have a basic understanding of php you could implement the code in your page (provided your page extensions are .php not .html and your server has php). I'm happy to share.

In terms of placing it on your page it depends on whether you are using css or a tabled design. I exclusively use css and minimise tables altogether. In css you just put the feed in a div and define the width, position etc in the stylesheet.


4:01 pm on Jan 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

thanks for the info triso..Yes, I know a very basic form pf php.

So, do I simply place the <rss>...</rss> code inside the php part of my .php page? will that suffice?


10:29 pm on Jan 24, 2006 (gmt 0)

5+ Year Member

What you need to do is to parse the rss feed that is in xml format to html. the xml at url news.google.com/news?ned=us&topic=t&output=rss is delineated by tags in the same way as html is.
each item has the following tags:

<guid isPermaLink="false"></guid>

php has a series of functions for parsing xml (check out php.net). the code I use to parse xml feeds is below. It is not as good as some other peoples code, but it works for the feeds I use. you may need to modify the code for google news, I have not used google news feeds.

just enter the url for the feed in the spot where i have --enter url for news feed here-- and you can change the number of news items and the length of th description also easily.


$MAXLINKCOUNT = 10; // (* 2) if =10, 5 news items will show

$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$linkcount = 0;

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
$tag = $name;
} elseif ($name == "ITEM") {
$insideitem = true;

function endElement($parser, $name) {

global $insideitem, $tag, $title, $description, $link, $linkcount, $MAXLINKCOUNT, $MAX_DESC_CHARS;
if ($name == "ITEM" && $linkcount <= $MAXLINKCOUNT) {
if (strlen($description) > $MAX_DESC_CHARS) {
$description = wordwrap($description, $MAX_DESC_CHARS, "-=CUT OFF HERE=-");
$pos = strpos($description, "-=CUT OFF HERE=-");
$description = trim(substr($description, 0, $pos)) . "...";
$description = htmlspecialchars(trim($description));
$description = str_replace("&amp;quot;", "&quot;", $description);
printf("<dt><b><a href='%s'>%s</a></b></dt>", trim($link),htmlspecialchars(trim($title)));
$title = "";
$description = "";
$link = "";
$insideitem = false;

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link, $linkcount;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
$description .= $data;
case "LINK":
$link .= $data;
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("--enter url for news feed here--","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 2048)) {
xml_parse($xml_parser, $data, feof($fp));



2:12 am on Jan 25, 2006 (gmt 0)

10+ Year Member

Webreference has a good tutorial and a script for converting RSS to HTML in perl. Just go to their site at search for rss2html

I am not sure if it removes the html but if you want a clean rss feed from most major and international news sites you can try the ones over at newslookup in the feeds section.


7:28 am on Jan 25, 2006 (gmt 0)

10+ Year Member

Is this how you display Scrolling news on your site...If not please let me know how I can display the scrolling news sepcific to my domain on my site.

I understand I need to create a database to store the feeds and then display it..right?


9:36 am on Jan 25, 2006 (gmt 0)

10+ Year Member

Did anyone try the php script as this looks really interesting / easy and if no one has tried it, I will try it today and report back!


10:00 am on Jan 25, 2006 (gmt 0)

5+ Year Member

I'm not sure what you mean by 'scrolling news'. I have not heard the term. This script simply parses a news feed of your choice to html. You can select a feed that is specifically relevant to your site.

The feed works really well for feeds that do not include html in the description tag. If the feed you want to use uses html in the description (like Google news) then you will need to edit the script.


10:13 am on Jan 25, 2006 (gmt 0)

10+ Year Member

I use magpierss, a free PHP library that does all the work. Very easy to install. Just unpack the archive and move it into a subdirectory.

Typical use is

$url = "http://rss.news.yahoo.com/rss/world";
$rss = fetch_rss($url);

Returned value $rss is an object with feed data and all items in an array. magpierss also has a built-in cache functionality.


10:24 am on Jan 25, 2006 (gmt 0)

10+ Year Member

when I say scrolling means, the news section is in a little box where the oldest news keep moving up and newest one pushes from below giving the impression that the whole text is scrolling upword.

I'm sure you must have seen on some sites specially project bidding sites where new project posted keep coming from below in side a box and old project move up.


2:33 pm on Jan 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

That was quite good piece of info from you people. I am still in the process of designing my pages and shall be including the RSS feed page very shortly. Thanks for all your help, and keep including other ways to include RSS feeds.

Featured Threads

Hot Threads This Week

Hot Threads This Month