Blogs, Tagging, RSS Feeds
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   SEO Chat ForumsSearch Engine StrategiesBlogs, Tagging, RSS Feeds

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread SEO Chat Forums Sponsor:
  #1  
Old August 22nd, 2005, 08:42 AM
TearingHairOut TearingHairOut is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Ireland
Posts: 144 TearingHairOut User rank is Private First Class (20 - 50 Reputation Level)TearingHairOut User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 2 h 29 m 15 sec
Reputation Power: 5
Handy script for displaying RSS 1.0 headlines

There are a number of scripts and third party services available for displaying RSS data on a web page, but in my experience this is the easiest to use. I got it to work with no prior knowledge of PHP.

It's designed for RSS 1.0, and originally appeared on:

www.sitepoint.com/article/php-xml-parsing-rss-1-0

I've mentioned this in an posting elsewhere before, but I tought it would be a good idea to make it available here in the new RSS/Tags/Blogs forum.

The good thing about this script is that, although its written in php, it can be inserted into pages with other extensions (e.g. .html) with just a little work on the .htacccess file (or on the control panel for IIS users). More about this towards the end of the post.

Firstly, the script itself. The following version of the script displays headlines only:

<?php

$insideitem = false;
$tag = "";
$title = "";
$link = "";

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

function endElement($parser, $name) {
global $insideitem, $tag, $title, $link;
if ($name == "ITEM") {
printf("<dt><b><a href='%s'>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
$title = "";
$link = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $link;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "LINK":
$link .= $data;
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://ENTER YOUR RSS FILE URL HERE","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>




And this version displays headlines and descriptions:



<?php

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

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;
if ($name == "ITEM") {
printf("<dt><b><a href='%s'>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://ENTER YOUR RSS FILE URL HERE","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>


In both cases, just replace the text 'ENTER YOUR RSS FILE URL HERE' with the location of the RSS file you wish to use.

To get this to work on a page with a .htm/.html extension, make the following adjustments:

Add the following lines of code to a .htaccess file (or create one if it isn't there already):

Removehandler .html .htm
AddType application/x-httpd-php .php .htm .html


If your site is hosted on IIS rather than Apache, .htaccess files will not work. Instead, there should be a facility to add additional file extensions to the php interpreter. Add .htm and/ or .html to the list as required. And that's it.

Hope this might be of some use to someone.

Reply With Quote
  #2  
Old August 24th, 2005, 07:18 PM
velepte velepte is offline
Registered User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 22 velepte User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 38 m 18 sec
Reputation Power: 0
Hi

My server is Apache, and I cannot find a file like that (htaccess) on my server. How do I create the file and are you sure this wont mess with my site at all?

Thanks for your help!!

Reply With Quote
  #3  
Old August 25th, 2005, 09:12 AM
TearingHairOut TearingHairOut is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Ireland
Posts: 144 TearingHairOut User rank is Private First Class (20 - 50 Reputation Level)TearingHairOut User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 2 h 29 m 15 sec
Reputation Power: 5
The .htaccess file is literally a file written in something like wordpad or notepad, and named .htaccess . There isn't generally one on the server already, you have to create it and put it there. Place it in your site's root folder.

One important point is that your server must support PHP for this to work. It would be an exception nowadays for any hosting server not to support PHP.

It shouldn't affect your site otherwise in any way. What this does is send your .html pages through the PHP interpreter on the server, so that the php code will work within the .html pages.

Any probs, PM me and I will try to help.

Reply With Quote
  #4  
Old August 25th, 2005, 10:41 PM
mhnlv's Avatar
mhnlv mhnlv is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Las Vegas
Posts: 246 mhnlv User rank is Lance Corporal (50 - 100 Reputation Level)mhnlv User rank is Lance Corporal (50 - 100 Reputation Level)mhnlv User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 6 Days 23 h 2 m 20 sec
Reputation Power: 5
Question Unable to get the script to work

RSS test page: http://www.vegasonesource.com/rss2.htm

After talking with Globat tech support I was advised the following commands are not allow in their .htaccess files. Any advice?
Ken: This are the list of directives that are not supported
Ken: Action
Ken: AddCharSet
Ken: AddEncoding
Ken: AddLanguage
Ken: AddType
Ken: BrowserMatch
Ken: BrowserMatchNoCase
Ken: CookieTracking
Ken: DefaultLanguage
Ken: DefaultType
Ken: ErrorDocument
Ken: ErrorHeader
Ken: Header
Ken: LanguagePriority
Ken: Options
Ken: PassEnv
Ken: Redirect
Ken: RedirectMatch
Ken: RedirectPermanent
Ken: RedirectTemporary
Ken: SetEnv
Ken: SetEnvIf
Ken: SetEnvIfNoCase

Thanks!

Mike
__________________
See that search box? It's there for a reason. Maybe, just maybe, the solution to your problem FASTER. Something to consider....

Gay Las Vegas
Discount Las Vegas show ticket
Gay hotel Las Vegas
Gay Lesbian Wedding Las Vegas

Last edited by mhnlv : August 25th, 2005 at 10:46 PM. Reason: Updated

Reply With Quote
  #5  
Old August 26th, 2005, 08:19 AM
TearingHairOut TearingHairOut is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Ireland
Posts: 144 TearingHairOut User rank is Private First Class (20 - 50 Reputation Level)TearingHairOut User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 2 h 29 m 15 sec
Reputation Power: 5
Quote:
Originally Posted by mhnlv
RSS test page: http://www.vegasonesource.com/rss2.htm

After talking with Globat tech support I was advised the following commands are not allow in their .htaccess files. Any advice?
Ken: This are the list of directives that are not supported
Ken: Action
Ken: AddCharSet
Ken: AddEncoding
Ken: AddLanguage
Ken: AddType
Ken: BrowserMatch
Ken: BrowserMatchNoCase
Ken: CookieTracking
Ken: DefaultLanguage
Ken: DefaultType
Ken: ErrorDocument
Ken: ErrorHeader
Ken: Header
Ken: LanguagePriority
Ken: Options
Ken: PassEnv
Ken: Redirect
Ken: RedirectMatch
Ken: RedirectPermanent
Ken: RedirectTemporary
Ken: SetEnv
Ken: SetEnvIf
Ken: SetEnvIfNoCase

Thanks!

Mike


If they don't allow the commands to be added to the .htaccess, there isn't much that can be done. It's not something that can be worked around to the best of my knowledge.

You would probably be better to use one of the third party scipts like rss2html. ( http://www.feedforall.com/free-php-script.htm ).

If you really wanted to use the script above, and you don't want to move hosting provider, you could in open a separate account elsewhere with just the rss file and a page with your layout template and the script. You could then link to it from your other pages saying something like "See latest news here". However, you still would not be able to include the script on any of your existing pages.

Reply With Quote
  #6  
Old August 31st, 2005, 04:45 AM
PaulS PaulS is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Brighton, UK
Posts: 115 PaulS User rank is Private First Class (20 - 50 Reputation Level)PaulS User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 36 m 58 sec
Reputation Power: 5
Just leave as a PHP file?

Why not just leave it as a .php file rather than a .htm/l? Then you would not need the command you're not allowed to use in the .htaccess file.

Alternatively, the script could be re-written to save the output in to a .html file, and run via a cronjob or by polling a .php file yourself by some other automated means. Admittedly, that's not exactly the drop-in solution first offered.
__________________
Work: Web Positioning Centre ---- Spiderability test & keyword report: Spider Test

Reply With Quote
  #7  
Old August 31st, 2005, 08:10 AM
mhnlv's Avatar
mhnlv mhnlv is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Las Vegas
Posts: 246 mhnlv User rank is Lance Corporal (50 - 100 Reputation Level)mhnlv User rank is Lance Corporal (50 - 100 Reputation Level)mhnlv User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 6 Days 23 h 2 m 20 sec
Reputation Power: 5
Smile

Thanks for the input! But you guys are talking way over my head.... I'm a FrontPage cut and paste kinda webmaster LOL. Anyhow, I did find a shortterm solution from http://www.rss-info.com/en_rssinclude-simple.html

So I just created a couple of different RSS pages and use the buttons to guide the uses to them. Clunky, but it works for now.



Mike

Reply With Quote
  #8  
Old August 31st, 2005, 08:27 AM
PaulS PaulS is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Brighton, UK
Posts: 115 PaulS User rank is Private First Class (20 - 50 Reputation Level)PaulS User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 36 m 58 sec
Reputation Power: 5
A meta tag you can also use

To help some software find the feed, you can put this in the <head> area of the page:

<link rel="alternate" type="application/rss+xml" title="RSS 0.91" href="http://www.example.com/feed.rss" />

Change 'RSS 0.91' to whatever your type of RSS is, and the href to whatever the URL of your feed is. This makes the 'live bookmarks' symbol come up in Firefox, and helps some auto-find software find your feed.

I'm sure Frontpage will let you put it in as a custom meta tag or something, or you might have to use whatever it has as a code view to put it in there.

Reply With Quote
  #9  
Old August 31st, 2005, 12:36 PM
TearingHairOut TearingHairOut is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Ireland
Posts: 144 TearingHairOut User rank is Private First Class (20 - 50 Reputation Level)TearingHairOut User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 2 h 29 m 15 sec
Reputation Power: 5
PaulS,

Thanks for the ideas.

The idea of keeping the file as a .html was related to situations where an existing page is having a feed parser added to it. Sometimes backlinks will point specifically at www.sitename.com/index.html, rather than just www.sitename.com.

Changing to a .php file might impact SERP's in this type of situation. Obviously, if it is a new website under development, or the feed is being added to a page of its own, creating the page as .php makes perfect sense.

Reply With Quote
  #10  
Old August 31st, 2005, 12:45 PM
PaulS PaulS is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Brighton, UK
Posts: 115 PaulS User rank is Private First Class (20 - 50 Reputation Level)PaulS User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 36 m 58 sec
Reputation Power: 5
Quote:
Originally Posted by TearingHairOut
The idea of keeping the file as a .html was related to situations where an existing page is having a feed parser added to it. Sometimes backlinks will point specifically at www.sitename.com/index.html, rather than just www.sitename.com.


Ah, of course, I should have guessed that.

In that case using PHP to create/save a new version of the .html file at regular intervals would be an easy way to get the same effect, without having the problem with the host not allowing the .htaccess change. Although to do this efficiently it would be best to run a cronjob to run the PHP file, and they might not allow you to set up one of those either.

Reply With Quote
  #11  
Old January 2nd, 2006, 01:54 AM
andrenym00 andrenym00 is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Location: NYC
Posts: 67 andrenym00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 27 m 36 sec
Reputation Power: 4
Quote:
Originally Posted by TearingHairOut
There are a number of scripts and third party services available for displaying RSS data on a web page, but in my experience this is the easiest to use. I got it to work with no prior knowledge of PHP.

It's designed for RSS 1.0, and originally appeared on:

www.sitepoint.com/article/php-xml-parsing-rss-1-0

I've mentioned this in an posting elsewhere before, but I tought it would be a good idea to make it available here in the new RSS/Tags/Blogs forum.

The good thing about this script is that, although its written in php, it can be inserted into pages with other extensions (e.g. .html) with just a little work on the .htacccess file (or on the control panel for IIS users). More about this towards the end of the post.

Firstly, the script itself. The following version of the script displays headlines only:

<?php

$insideitem = false;
$tag = "";
$title = "";
$link = "";

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

function endElement($parser, $name) {
global $insideitem, $tag, $title, $link;
if ($name == "ITEM") {
printf("<dt><b><a href='%s'>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
$title = "";
$link = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $link;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "LINK":
$link .= $data;
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://ENTER YOUR RSS FILE URL HERE","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>




And this version displays headlines and descriptions:



<?php

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

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;
if ($name == "ITEM") {
printf("<dt><b><a href='%s'>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://ENTER YOUR RSS FILE URL HERE","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>


In both cases, just replace the text 'ENTER YOUR RSS FILE URL HERE' with the location of the RSS file you wish to use.

To get this to work on a page with a .htm/.html extension, make the following adjustments:

Add the following lines of code to a .htaccess file (or create one if it isn't there already):

Removehandler .html .htm
AddType application/x-httpd-php .php .htm .html


If your site is hosted on IIS rather than Apache, .htaccess files will not work. Instead, there should be a facility to add additional file extensions to the php interpreter. Add .htm and/ or .html to the list as required. And that's it.

Hope this might be of some use to someone.


What would I need to add to the code to get multiple feed sources onto one feed? For example: yahoo search feed on several keywords?

Reply With Quote
  #12  
Old January 3rd, 2006, 03:06 PM
TearingHairOut TearingHairOut is offline
Contributing User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Ireland
Posts: 144 TearingHairOut User rank is Private First Class (20 - 50 Reputation Level)TearingHairOut User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 2 h 29 m 15 sec
Reputation Power: 5
andrenym00,

I'm sorry but I don't know how you might incorporate multiple feeds into the script so that they appear as they are published.

The only thing I might suggest is that you could place the script on your page more than once, and write in the feed that you want each time. That way, all the items from each feed would appear together, e.g.

Feed 1 story 1
Feed 1 story 2
Feed 2 story 1
Feed 2 story 2
Feed 2 story 3
Feed 3 story 1
etc...

However, I don't think that's what you want. Maybe if you read some of the other threads in this forum you might get a feel for some of the other scripts that are around. One of them might fit your requirements better.
__________________
That's all very well in practice, but will it work in theory?
Visit MadeForOne.com, which markets personalized gifts in many different categories. New to SEOChat? Look at the FAQ's for answers to many of the most common questions.

Reply With Quote
  #13  
Old December 14th, 2007, 09:57 AM
tintin75 tintin75 is offline
Registered User
SEO Chat Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 1 tintin75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 28 sec
Reputation Power: 0
Dragging up a very old thread here, but how could this script be modified to only display the first n entries from an RSS feed, rather than every entry?

Reply With Quote
Reply

Viewing: SEO Chat ForumsSearch Engine StrategiesBlogs, Tagging, RSS Feeds > Handy script for displaying RSS 1.0 headlines


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread