Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

   

Reply
 
LinkBack Thread Tools Display Modes
Old 12-14-2004, 03:04 PM   #1 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
Issue with multiple feeds on the same page

I'm trying to set up a "News Extra" page in addition to my news blog - to do so I'm bringing together a number of media rss/xml feeds, each in their own cell.

However, some of it just plain isn't working, with what should be a display from one feed simply repeating on other feeds, and also not the full file being displayed.

Here's the page:
http://www.platinax.co.uk/news/extra/

The Security focus cell sometimes shows 1 or 2 stories, or just copies the Reuters - once it actually showed 20 when I mixed the feeds around.

There's also a problem with the Sitepoint and O-Reilly feeds, too.

I think I must be missing something important in the construction of these feeds.

So far I'm simply using the following code:

Code:
<?php $xmlfile = fopen("http://news.bbc.co.uk/rss/newsonline_uk_edition/business/rss091.xml", "r"); if(!$xmlfile)die("cannot open the xml file"); $readfile = fread($xmlfile ,40000); $searchfile = eregi("<item>(.*)</item>", $readfile ,$arrayreg); $filechunks = explode("<item>", $arrayreg[0]); $count = count($filechunks); echo "<table class='featuretable2'>"; for($i=1 ; $i<=$count-1 ;$i++) { ereg("<title>(.*)</title>",$filechunks[$i], $title); ereg("<link>(.*)</link>",$filechunks[$i], $links); echo "<tr><td>"; echo "<a href ='$links[1]'\>$title[1]</a>"; echo "</td></tr>"; } echo "</table>"; ?>
Are there any known problems with bringing multiple feeds together?

I'm really stuck on figuring out why not all feeds are showing, and why almost none are showing their actual full feed of 20 items.

Any pointers most appreciated.
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-14-2004, 05:20 PM   #2 (permalink)
v7n Mentor
 
imaginemn's Avatar
 
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,946
iTrader: 0 / 0%
Latest Blog:
None

imaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to all
Send a message via MSN to imaginemn Send a message via Yahoo to imaginemn Send a message via Skype™ to imaginemn
The only thing I can think of if you are using the same code for multiple feeds make sure the variables are either defined differently (unique) for each feed or make sure you clear it after using the data. It may be displaying the last defined data instead of updating the content if the feed is blank or cannot connect.

imaginemn
__________________
Need a project done? - Set Your Own Price!
Imagine Creative Services
- Design : Marketing : Multimedia : More
imaginemn is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-15-2004, 02:14 AM   #3 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
Thanks for the comments - much appreciated, and they make sense - I'm using the exact same php code for each feed - all values the same. Spot who isn't used to dealing with programming.

I tried changing the variables, simply by adding a number to the end of each one, but that simply killed the feeds.

Quote:
or make sure you clear it after using the data
This looks like it could be the easiest method - do you have any suggestions of how I may do that?
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-15-2004, 10:41 AM   #4 (permalink)
v7n Mentor
 
imaginemn's Avatar
 
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,946
iTrader: 0 / 0%
Latest Blog:
None

imaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to all
Send a message via MSN to imaginemn Send a message via Yahoo to imaginemn Send a message via Skype™ to imaginemn
I would create a function like this.

Code:
<?php function get_feed($source) { $xmlfile = fopen($source, "r"); if(!$xmlfile)die("cannot open the xml file"); $readfile = fread($xmlfile ,40000); $searchfile = eregi("<item>(.*)</item>", $readfile ,$arrayreg); $filechunks = explode("<item>", $arrayreg[0]); $count = count($filechunks); echo "<table class='featuretable2'>"; for($i=1 ; $i<=$count-1 ;$i++) { ereg("<title>(.*)</title>",$filechunks[$i], $title); ereg("<link>(.*)</link>",$filechunks[$i], $links); echo "<tr><td>"; echo "<a href ='$links[1]'\>$title[1]</a>"; echo "</td></tr>"; } echo "</table>"; $xmlfile = ""; $readfile = ""; $searchfile = ""; $filechunks = ""; $count = ""; $source = ""; $i = ""; $links = ""; $title = ""; } ?>
And call each feed like this.

Code:
<?php get_feed("http://news.bbc.co.uk/rss/newsonline_uk_edition/business/rss091.xml"); ?>
imaginemn
__________________
Need a project done? - Set Your Own Price!
Imagine Creative Services
- Design : Marketing : Multimedia : More
imaginemn is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-15-2004, 10:50 AM   #5 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
You need to make sure that you close the file after you have read from it.

Put the following on the end of each of your feeds (right after you close out the table).

Code:
fclose($xmlfile);
That way, if it does not open the xml file, it will display the error (right now, it will never display the error so long as you can open the first feed).

Another alternative is to use file_get_contents instead of fopen and fread. This will read the entire file into a string variable. An example:

Code:
$xmlfile = file_get_contents("http://news.bbc.co.uk/rss/newsonline_uk_edition/business/rss091.xml");
That will read the xml feed into the $xmlfile variable, from there, you can proceed with extracting the different parts. I would actually suggest using preg_match_all instead of eregi just because of speed differences and preg_match_all will separate all of the matches into their own arrays. Here's an example that uses file_get_contents and preg_match_all:

Code:
<?php $xmlfile = file_get_contents ("http://news.bbc.co.uk/rss/newsonline_uk_edition/business/rss091.xml"); if (empty($xmlfile)) die("failed to connect to xml feed"); preg_match_all("|<item>(.*)</item>|sU", $xmlfile, $items); $itemlist = array(); foreach ($items[1] as $key => $item) { preg_match("|<title>(.*)</title>|s", $item, $title); preg_match("|<link>(.*)</link>|s", $item, $link); $itemlist[$key]['title'] = $title[1]; $itemlist[$key]['link'] = $link[1]; } // Display all article titles, linking them to the actual story foreach ($itemlist as $item) { echo '<a href="' . $item['link'] . '">' . $item['title'] . '</a><br>'; } echo '<hr>'; // Just here for separation of the two methods for displaying // Alternative - set how many articles you want to display for ($i = 0; $i < 5; $i++) // Change '5' to the number of articles you would like to show { echo '<a href="' . $itemlist[$i]['link'] . '">' . $itemlist[$i]['title'] . '</a><br>'; } $xmlfile = ""; // empty out the xmlfeed variable so that you can test the next one. ?>
I'm sure there is probably some redundancy in there, but... hopefully it will work out...
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-15-2004, 12:08 PM   #6 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
Many thanks for the help - the feeds are looking much improved.

For some reason a couple of them aren't worknig at all - but that seems to be an issue I'll take up with the individual vendors.

Thanks again - much appreciated. I've given Imagine Creative a free listing in the Platinax Directory - insitedev, if you would like to suggest a site, feel free.
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-15-2004, 01:11 PM   #7 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
I would suggest Insite's website, but we are still in the process of creating it. Perhaps later?
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-16-2004, 07:49 AM   #8 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
No problem - just PM me when you're ready.
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-16-2004, 08:09 AM   #9 (permalink)
v7n Mentor
 
imaginemn's Avatar
 
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,946
iTrader: 0 / 0%
Latest Blog:
None

imaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to all
Send a message via MSN to imaginemn Send a message via Yahoo to imaginemn Send a message via Skype™ to imaginemn
I, Brian thanks for the link even though it's not necessary. I appreciate it. Did you ever figure out what was going on with the feeds that were not working?

imaginemn
__________________
Need a project done? - Set Your Own Price!
Imagine Creative Services
- Design : Marketing : Multimedia : More
imaginemn is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-17-2004, 08:45 AM   #10 (permalink)
v7n Mentor
 
Johan007's Avatar
 
Join Date: 10-15-03
Posts: 1,932
iTrader: 0 / 0%
Latest Blog:
None

Johan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to allJohan007 is a name known to all
Quote:
Originally Posted by I, Brian
Are there any known problems with bringing multiple feeds together?
Multiple feeds hit the server very hard and page load slowly (though yours seems to run fast). You could implement caching the information ever 2 hours?

Good job and much better looking than what I have done.
Johan007 is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Submit Feeds to my directory get MULTIPLE backlinks GeorgeB Web Directory Issues 7 04-07-2006 05:03 AM
Multiple Adsense/page! thebassman Contextual Networks 22 09-07-2004 01:11 PM
Multiple CSS Classes on a Page? amyinomaha Coding Forum 9 12-03-2003 07:14 AM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 03:13 AM.
© Copyright 2008 V7 Inc