473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Integrating RSS feed into a website..

I would like to integrate an RSS newsfeed into my website but can't
seem to figure out how.
Has anyone got any pointers for me?

E.
Jul 17 '05 #1
5 3542
Mayhem wrote:
I would like to integrate an RSS newsfeed into my website but can't
seem to figure out how.
Has anyone got any pointers for me?

E.

Yeah, search http://google.com and http://php.net for "PHP XML" or "PHP RSS
PARSING". There are dozens of sites that will tell you how to do this
already out there.
Jul 17 '05 #2
Mayhem wrote:
I would like to integrate an RSS newsfeed into my website but can't
seem to figure out how.
Has anyone got any pointers for me?

E.


use XSLT.

You will need to write an XSL template to convert the raw RSS formatted
XML into whatever HTML you want.

This might work:

$xh = xslt_create();
$html = xslt_process($xh, 'http://theSource/info.rss', 'rss2xhtml.xsl');
echo $html;

You will obviously have to provide 'rss2xhtml.xsl'. See zvon.org for
tutorials and a crash course in writing XSLT templates.

don't concern yourself with parsing RSS. XML parsing built into the XSLT
processor will be enough for your needs.

If you're struggling with XSLT, join this mailing list, they are very
helpful. http://www.mulberrytech.com/xsl/xsl-list/index.html

Once you can do basic XML/XSLT transformations, you'll wonder how you
ever lived without it.

Also, if you're lazy ;)
you might want to check this out
http://www.2rss.com/index.php?rss=5894
Jul 17 '05 #3
On Thu, 22 Apr 2004 23:15:41 +0200, Mayhem in comp.lang.php wrote:
I would like to integrate an RSS newsfeed into my website but can't
seem to figure out how.
Has anyone got any pointers for me?


I had the same issue a few weeks ago. Using Google, I found a snippet which I
adapted to my needs. Here's something you might be able to work with;

<?php
$_item = array();
$_depth = array();
$_tags = array("dummy");

function initArray()
{
global $_item;

$_item = array ("TITLE"=>"", "LINK"=>"",
"DESCRIPTION"=>"", "URL"=>"");
}

function startElement($parser, $name){
global $_depth, $_tags, $_item;

if (($name=="ITEM") ||
($name=="CHANNEL")
|| ($name=="IMAGE")) {
initArray();
}
@$_depth[$parser]++;
array_push($_tags, $name);
}

function endElement($parser, $name){
global $_depth, $_tags, $_item;

array_pop($_tags);
$_depth[$parser]--;
switch ($name) {
case "ITEM":
echo "<p><a href=\"{$_item['LINK']}
\">" .
"{$_item['TITLE']}</a></p>\n";
initArray();
break;

case "IMAGE":
echo "<a href=.{$_item['LINK']}.>" .
"<DEFANGED_IMG src=.{$_item
['URL']}. " .
"alt=.{$_item['TITLE']};
border=.0.></a>\n<br />\n";
initArray();
break;

case "CHANNEL":
echo "<h3>{$_item['TITLE']}</h3>\n";
initArray();
break;
}
}

function parseData($parser, $text){
global $_depth, $_tags, $_item;

$crap = preg_replace ("/\s/", "", $text);
/* is the data just whitespace?
if so, we don't want it! */

if ($crap) {
$text = preg_replace ("/^\s+/", "", $text);
/* get rid of leading whitespace */
if (@$_item[$_tags[$_depth[$parser]]]) {
$_item[$_tags[$_depth[$parser]]] .=
$text;
} else {
$_item[$_tags[$_depth[$parser]]] =
$text;
}
}
}

function parseRDF($file){
global $_depth, $_tags, $_item;

$xml_parser = xml_parser_create();
initArray();

/* Set up event handlers */
xml_set_element_handler
($xml_parser, "startElement", "endElement");
xml_set_character_data_handler
($xml_parser, "parseData");

/* Open up the file */
$fp = fopen ($file, "r") or die ("Could not
open $file for input");

while ($data = fread ($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof
($fp))) {
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);
}

parseRDF
("http://freshmeat.net/backend/fm-releases.rdf");
#("http://www.theregister.co.uk/headlines.rss");
?>

<br />
<h2>Latest Headlines From Newsforge</h2>
<?php
/* declare different RSS feed. Since the code to parse source is
* already listed, all one needs to do is list the new source as
* follows*/
parseRDF("http://www.newsforge.com/newsvac.rss");

Replace the last line, with whatever source you wish to parse.

There are some varations out there, were one can cache the file in a dbase, so
that each time teh page is loaded it doesn't hit the remote server everytime.
But, I'll leave that as an exercise for you to find. ;)

HTH.

--
S.Allen
-------------------------------------------
barnyard Sunday Apr 25 2004 11:10:02 PM EDT
-------------------------------------------
Ver o que é justo e não agir com justiça é a maior das covardias
humanas.
-- Confúcio
Jul 17 '05 #4
In article <sl**************@barnyard.sweetpig.dyndns.org>, marathon wrote:
On Thu, 22 Apr 2004 23:15:41 +0200, Mayhem in comp.lang.php wrote:
I would like to integrate an RSS newsfeed into my website but can't
seem to figure out how.
Has anyone got any pointers for me?


I had the same issue a few weeks ago. Using Google, I found a snippet which I
adapted to my needs. Here's something you might be able to work with;


[snip code]

Or you could simply use the code at http://magpierss.sf.net
Jul 17 '05 #5
I set up an rss feed then documented exactly how I did it on this page:
http://www.yourweb.name/
It definitely isn't the only way or the best way, but it works.

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
2
by: Charles Stricklin | last post by:
If I have an RSS newsfeed like this: <?xml version="1.0" encoding="utf-8"?><!-- generator="whocares" --> <rss version="0.92"> <channel> <title>Website Name</title>...
0
by: Julian | last post by:
I have written a CGI program which takes an RSS feed and turns it into HTML. I'm using it to display the latest headlines from the BBC News website. The question is, what order should I display...
1
by: hp_1981 | last post by:
Hi My website is a web directory like dmoz and yahoo directory. Can I let webmasters or even weblog owners to have a copy of my site, allowing them to present it the way they want to, by...
1
by: nostradamus | last post by:
Hi! We need to integrate an RSS feed in a webpage using ASP. I've been testing out the great script at ByteScout: http://bytescout.com/how_to_display_rss_using_asp.html It worked very...
6
by: affiliateian | last post by:
Total newbie here for this so please be patient. We manually update our XML feed when we publish an article on our website. Can we add a javascript tracking pixel (from phpadsnew) into the XML...
0
by: johndparker | last post by:
Hi, I have a ASP.NET web application I distribute precompiled (without source code) to clients. This can be run as a standalone web app but I would also like the option of the client integrating...
1
by: shotokan99 | last post by:
hi guys, i want to have rss on my site and the page is written in php (mypage.php). what are the things i need? how to start to with it? pls help.. tnx
10
by: bhass | last post by:
From my other post I am making a simple program that creates an RSS feed with Python. Now when I run my program so far, I get errors. It says "something is not defined". The word something is...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.