Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-14-2007, 11:25 AM PHP RSS Help!
Ultra Talker

Posts: 298
Trades: 3
Hi!

I have a simple parser for an rss feed, and it works fine, but....

I want to make it so multiple feeds can be added and it will display them by date, from each of the feeds.

eg.

Number 1 feed from google 10/10/07 1pm
mumber 2 feed from yahoo 10/10/07 12.32pm
number 3 fedd from bcc news 10/10/07 12.12pm

(hope i explained it clearly enough!)

PHP Code:
<?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('<p><b><a href=\'%s\'>%s</a></b><br>',
   
trim($link),trim($title));
  
printf('%s</p>'."\n",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://www.liverpoolecho.co.uk/everton-fc/everton-fc-news/rss.xml','r')
or die(
'Error reading RSS data.');
while (
$data fread($fp4096)) {
 
xml_parse($xml_parser$datafeof($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);




?>
thanks for you help
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Last edited by Tropica; 10-14-2007 at 11:27 AM..
Tropica is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-14-2007, 05:19 PM Re: PHP RSS Help!
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Why not use an array?

For example:
PHP Code:
$array[1] = "example1.com/rss.rss";
$array[2] = "example2.com/rss.rss";
$array[3] = "example3.com/rss.rss";

foreach(
$array as $value){
// read rss for this one.

__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 10-14-2007 at 05:21 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-14-2007, 06:27 PM Re: PHP RSS Help!
Ultra Talker

Posts: 298
Trades: 3
ok sounds great, but where would i insert it? lol
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Tropica is offline
Reply With Quote
View Public Profile
 
Old 10-14-2007, 06:37 PM Re: PHP RSS Help!
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
ok, try:

PHP Code:
<?php
$insideitem 
false;
$tag '';
$title '';
$description '';
$link '';

$array[1] = "example1.com/rss.xml";
$array[2] = "example2.com/rss.xml";
$array[3] = "example3.com/rss.xml";

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('<p><b><a href=\'%s\'>%s</a></b><br>',
   
trim($link),trim($title));
  
printf('%s</p>'."\n",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;
 }
 }
}

foreach(
$array as $urltoread){ 
$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser'startElement''endElement');
xml_set_character_data_handler($xml_parser"characterData");
$fp fopen("$urltoread",'r')
or die(
'Error reading RSS data.');
while (
$data fread($fp4096)) {
 
xml_parse($xml_parser$datafeof($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);




?>
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 10-14-2007 at 06:38 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-15-2007, 05:09 AM Re: PHP RSS Help!
Ultra Talker

Posts: 298
Trades: 3
works great!! Thanks Rogem002!!

Sorry to ask more of you, but is it possible to sort them in date order regardless of feed? So the newest from whichever feed is at the top?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Tropica is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP RSS Help!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19114 seconds with 12 queries