...

View Full Version : RSS Feeds - General how-to question



YaymeQ
02-14-2008, 04:38 AM
Okay, I know the thing about googling my question before posting and it's probably right in front of my face but I don't know what I'm talking about so searching for it isn't helping. I know how to subscribe and all that for personal use but what I want to do, is have it on the site I'm making. I want a news area people can go to on my site that displays an rss feed I've subscribed to. Is that possible? Like "My Yahoo" displays the feeds I pick and all I have to do is go there. Or is that a module? (What is a module anyway?) Only I don't want them to customize it I just want a news area on my site that's automatically updated for me. That's it.

elkdanger
02-14-2008, 08:58 AM
An RSS feed is essentially an Xml file which contains certain fields in a certain format - that's it.

Have a look at the specifications (http://www.rss-specifications.com/rss-specifications.htm) to see the formats available.

All you have to do is basically print out your news items or whatever according to the RSS format, make sure the response content-type of the page is set to "application/xml" (there might be an rss-specific mime-type, i don't know) and you're good to go.

Since there are a few different formats you might want to choose to adhere to v2 and send it across to Feedburner (http://www.feedburner.com/fb/a/about) which I believe standardises the output a bit so it can reach the majority of readers out there, aswell as giving you some nice stats.

Hope that gives you a start.

FJbrian
02-14-2008, 01:37 PM
There's a large number of scripts on the web to do this for you. Sorta plug em' in and they do the work.
Try googling RSS Static
then Zebrafeeds by Laurent Cazalet
Even more complex, My Headlines by Mike Agar
PHPClasses.org also has some
Google's developer section has a nice one that's not so hard to customize
There's alot out there

I'd recommend Zebrafeeds.
MyHeadlines gives people headaches installing, no doubt. However it's setup wonderfully and in my opinion he's coverred most every use you could have for RSS including offerring your combined feeds as one single feed for others to use in their newsreaders(besides seeing it on the site) I'm guessing his site is jmagar.com

mlseim
02-14-2008, 01:47 PM
YaymeQ ...

It's actually very easy to do.
Give me a URL for a feed you want to use on your site,
then I'll give you a simple working example.

(and are you using PHP5?)

YaymeQ
02-14-2008, 05:19 PM
http://www.washingtonpost.com/wp-dyn/rss/realestate/index.xml

I don't know if that's the one I'll end up using but it'll work for the purpose of demonstration.

as far as using php5 ... at the moment I'm not using anything. Well, besides html/css but that's a given.

mlseim
02-14-2008, 06:24 PM
I assume your webhost allows PHP scripting?

You'll need to change the extension to .php
Example "index.php" instead of "index.html"

I'm working on an example for the feed.

mlseim
02-14-2008, 06:30 PM
You will stick the code below into the area on your page where the feed will appear.
I deliberately did no formatting for the text, because it will be using your own CSS
for the <div> or <table> where you place the code.

Your page needs to have the extension of .php ... or you need to have your .html
extensions processed as PHP (ask your webhost about that).

Here is my working example:
http://www.catpin.com/yaymeq.php

Here is the PHP script:


<?php
// rss page for Washington Post -
$feed_url = "http://www.washingtonpost.com/wp-dyn/rss/realestate/index.xml";

# INITIATE CURL.
$curl = curl_init();

# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

# GRAB THE XML FILE.
$xmlTwitter = curl_exec($curl);

curl_close($curl);

# SET UP XML OBJECT.
# Use either one of these, depending on revision of PHP.
# Comment-out the line you are not using.
//$xml = new SimpleXMLElement($xmlTwitter);
$xml = simplexml_load_string($xmlTwitter);

// How many items to display
$count = 5;

// How many characters from each item
// 0 (zero) will show them all.
$char = 200;

foreach ($xml->channel->item as $item) {
if($char == 0){
$newstring = $item->description;
}
else{
$newstring = substr($item->description, 0, $char);
}
if($count > 0){
//in case they have non-closed italics or bold, etc ...
echo"</i></b></u></a>\n";
echo"
<div style='font-family:arial; font-size:.8em;'>
<b>{$item->title}</b><br />
$newstring ... <a href='{$item->guid}'>read more</a>
<br /><br />
</div>
";
}
$count--;
}
?>

YaymeQ
02-14-2008, 06:40 PM
Hey thanks! Yes my webhost allows php scripting I just don't know anything about it, besides recognizing comments, so I tend to not mess with it ... yet anyway. My site has to be up by saturday so after that I'm going to try to learn a bit more so I'm not stumbling through this so much. Thank you so much!

YaymeQ
02-14-2008, 06:46 PM
Oh! and if I save my html file as a php file all the html will still be read as html right? So it'll still display like the rest of the pages?

mlseim
02-14-2008, 06:53 PM
Save a copy of your original .html file.

Make a new copy and change the extension to .php
Put the script I gave into a spot on the new page (inside your <table> or <div>).
Include the <?php and ?> part of the script when you insert it.

Upload your new .php file and enter URL by it's new name (mypage.php ... or whatever).

It will either work or not, depending on the version of PHP your webhost uses.
If they are using PHP4, I don't think the CURL functions will work.

I realize this whole POST should be in the PHP part of this forum, but I cannot
move it (I'm not a moderator). Anyhow, others might find it useful.

EDIT:
and if it works, let us see your website.

.

YaymeQ
02-14-2008, 07:17 PM
yeah sorry about that, I hadn't realized this was going to end up as a php post. Just some followup info, my host does use php 5 but it has to be saved as .php5 not .php or it will automatically read as php4 (Just got done checking the faq).

Edit: My website isn't up yet, I have a placeholder there right now, I'm just testing to make sure everything works before I make it live. but in a few days I can come back and let you know.

mlseim
02-14-2008, 08:06 PM
extension of .php5 is fine.

You can also ask them about processing all of your .html files as .php5
so you don't need to worry about extensions.

Keep in mind that once you have a .php file, you can't view it offline
like a normal .html file. PHP is processed by your server (webhost), not
on your PC.

That's why I mentioned making a "saved" copy of your original .html file,
in case you're using Dreamweaver or something to create your html pages.

You'll soon realize the power of PHP and be hooked on it ... dynamically
generating pages without the trouble of static .html pages.
Content management is what it's all about.

YaymeQ
02-14-2008, 09:18 PM
Well, actually I'm hand coding everything. I realize I could use some type of wysiwyg editor but I tried it and the code is unreadable to me. I have go-live but I also want to actually learn the coding languages better. So no dreamweaver. I'm hoping php will be as easy as html was to pick up, but I'll do that after my deadline. The site looks really amaturish right now but I'm not sure how to make it look better, later I'll go to the "review my site" section and see what people say. lol I'm anticipating a lot of CC. hopefully.

mlseim
02-14-2008, 10:14 PM
Hand-coding is best.

As for the RSS reader....

If you just take the script above and save it as "yaymeq.php5"
and upload it, you should be able to see the same thing
as my test: http://www.catpin.com/yaymeq.php

You of course would use your own domain name ...

That would tell you if it's working and PHP5 is configured OK.

For your "amateurish" site, if you have a copyright date on
the bottom of your page, you can change 2008 to <?=date("Y")?>
It will always show the current year and switch to 2009 automatically.

That's the power of PHP.

YaymeQ
03-19-2008, 01:27 AM
Okay I know it's been a while but it you go to http://webuynovahouses.com/realestatenews.php5

I only copied and pasted the code because I don't know php yet (I got a book though!) so you see that error ... how do I fix that?


foreach ($xml->channel->item as $item) {
if($char == 0){
$newstring = $item->description;
}

That's the piece of code it deals with.

EDIT:
stupid question ... I fixed it ... bad url ... eh heh heh

but you still said you wanted to see the site! So there it is!

crosswire
03-19-2008, 05:47 PM
You will stick the code below into the area on your page where the feed will appear.
I deliberately did no formatting for the text, because it will be using your own CSS
for the <div> or <table> where you place the code.

Your page needs to have the extension of .php ... or you need to have your .html
extensions processed as PHP (ask your webhost about that).

Here is my working example:
http://www.catpin.com/yaymeq.php

Here is the PHP script:


<?php
// rss page for Washington Post -
$feed_url = "http://www.washingtonpost.com/wp-dyn/rss/realestate/index.xml";

# INITIATE CURL.
$curl = curl_init();

# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

# GRAB THE XML FILE.
$xmlTwitter = curl_exec($curl);

curl_close($curl);

# SET UP XML OBJECT.
# Use either one of these, depending on revision of PHP.
# Comment-out the line you are not using.
//$xml = new SimpleXMLElement($xmlTwitter);
$xml = simplexml_load_string($xmlTwitter);

// How many items to display
$count = 5;

// How many characters from each item
// 0 (zero) will show them all.
$char = 200;

foreach ($xml->channel->item as $item) {
if($char == 0){
$newstring = $item->description;
}
else{
$newstring = substr($item->description, 0, $char);
}
if($count > 0){
//in case they have non-closed italics or bold, etc ...
echo"</i></b></u></a>\n";
echo"
<div style='font-family:arial; font-size:.8em;'>
<b>{$item->title}</b><br />
$newstring ... <a href='{$item->guid}'>read more</a>
<br /><br />
</div>
";
}
$count--;
}
?>


Hi there,
I current use 6 rss feeds on my website and since they all use an online site coding and javascript, (http://rss.budgetwebdesign.org/) it really slows down the main page.
I was hoping to create it in php and found your code above
I understand from the prev post but having issues trying to see if i can embed the code myself on a test page.
Here is the test page online.And yes my host server does do php.
http://lukper5.freehostia.com/test.php
and here is my rss feed i want to add
http://www.lexisnexis.ca/updates/whatsnewtlw.xml

PLease note that I will be using 5 other rss feeds at various places around the main page.
Any help.
Thanks

mlseim
03-19-2008, 08:26 PM
Crosswire ...

Because you're getting a function error, I'm guessing your webhost does not allow
PHP CURL functions, or has something disabled with your configuration. Maybe they
are using an old version of PHP?

Here's something to try ... take the code below and save it as "test.php". Upload it
and open that URL. It should display the whole information about your website server.
Look for sections on PHP revision, CURL, etc. and see what it shows for configuration.

Here is the test script ... use it to see your info, but delete it afterwards
so nobody else can access it.



<?php
// This will display your server information ...
phpinfo();
?>



You should see a section like this ...

curl
CURL support enabled
CURL Information libcurl/7.15.3 OpenSSL/0.9.7e zlib/1.2.3

crosswire
03-20-2008, 02:18 PM
hi thanks for the tip
Ok it says that i have PHP Version 4.4.0 and nothing about curl but something aboutt it in a box

Configure Command

'./configure' '--with-mysql=/usr' '--with-gd' '--with-gzip' '--with-zlib' '--with-kerberos' '--enable-ftp' '--enable-gd-native-ttf' '--with-imagick' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-xpm-dir=/usr' '--with-png-dir=/usr' '--with-imagick=/usr' '--enable-bcmath' '--with-xml' '--with-dom' '--with-gettext' '--enable-mbstring' '--with-curl' '--with-imap' '--enable-calendar' '--enable-mhash' '--enable-openssl' '--with-openssl=/usr' '--enable-exif' '--with-mhash=/usr' '--enable-mcrypt' '--with-mcrypt=/usr' '--with-imap-ssl' '--enable-xslt' '--with-dom-xslt=/usr' '--with-xslt-sablot=/usr'

mlseim
03-21-2008, 03:23 AM
In that case, look at Magpie, which uses fopen() to read an XML.
That might work in your case.

http://magpierss.sourceforge.net/

Skyzyx
03-24-2008, 06:36 PM
I gonna go ahead and plug SimplePie here because it's faster, easier, and better than Magpie.

However, if you're not much of a PHP coder at all, Feed Digest (http://feeddigest.com) *might* be a better solution for you.

mlseim
03-24-2008, 07:54 PM
Skyzyz ...
Thanks for providing that tip ... I use CURL, so I'm not much of a Magpie SimplePie expert.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum