Current location: Hot Scripts Forums » Programming Languages » PHP » Restricting the results my xml feed returns


Restricting the results my xml feed returns

Reply
  #1 (permalink)  
Old 12-31-04, 12:42 PM
cardesign cardesign is offline
Newbie Coder
 
Join Date: Mar 2004
Location: UK
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Restricting the results my xml feed returns

I have got a bit of code which returns all of the headlines inside the newsfeed stated, but as this takes up quite a bit of space I want to limit the headlines it returns to the first 10.

The current demo which returns them all is at http://www.blueuniverse.co.uk/news.php

The code I am using is

PHP Code:

            <?
 $xml_file 
"http://p.moreover.com/cgi-local/page?c=3M%20news&o=xml";//change this to whatever news feed you want to use
 
$open_tags = array(
 
"ARTICLE" => "<ARTICLE>",
 
"HEADLINE_TEXT" => "<HEADLINE_TEXT>",
 
"URL" => "<URL>",
 
"HARVEST_TIME" => "<HARVEST_TIME>",
 
"SOURCE" => "<SOURCE>"); $close_tags = array(
 
"ARTICLE" => "</ARTICLE>",
 
"HEADLINE_TEXT" => "</HEADLINE_TEXT>",
 
"HARVEST_TIME" => "<HARVEST_TIME>",
 
"URL" => "</URL>",
 
"SOURCE" => "</SOURCE>"); $count=0;
 function 
startElement($parser$name$attrs=""){
 global 
$open_tags$temp$current_tag;
 
$current_tag $name;
 if (
$format $open_tags[$name]){
 switch(
$name){
 default:
 break;
 }
 }
 } function 
endElement($parser$name$attrs=""){
 global 
$close_tags$temp$current_tag$count$numstors;
 if (
$format $close_tags[$name]){
 switch(
$name){
 case 
"ARTICLE":
 
return_page($temp);
 
$temp "";
 break;
 default:
 break;
 }
 }
 } function 
characterData($parser$data){
 global 
$current_tag$temp$catID;
 switch(
$current_tag){
 case 
"HEADLINE_TEXT":
 
$temp["head"] = $data;
 
$current_tag "";
 break;
 case 
"URL":
 
$temp["url"] = $data;
 
$current_tag "";
 break;
 case 
"SOURCE":
 
$temp["source"] = $data;
 
$current_tag "";
 break;
 case 
"HARVEST_TIME":
 
$temp["time"] = $data;
 
$current_tag "";
 break;
 default:
 break;
 }
 } function 
return_page(){
 global 
$temp$count;
 
$temp["time"] = preg_replace ("/AM/"" a.m."$temp["time"]);
 
$temp["time"] = preg_replace ("/PM/"" p.m."$temp["time"]);
 echo 
"<a href=\"".$temp["url"]."\" target=\"_blank\">".$temp["head"]."</a>\n<br />\n";
 echo 
"[".$temp["source"]."] - ".$temp["time"]."\n<br />\n<br />\n\n";
 } 
$xml_parser xml_parser_create();
 
xml_set_element_handler($xml_parser"startElement","endElement");
 
xml_set_character_data_handler($xml_parser"characterData"); if (!($fp fopen($xml_file"r"))) {
 die(
"Could not open $xml_file for parsing!\n");
 }
 while (
$data fread($fp4096)) {
 if (!(
$data utf8_encode($data))) {
 echo 
"ERROR"."\n";
 }
 if (!
xml_parse($xml_parser$datafeof($fp))) {
 die(
sprintf"XML error: %s at line %d\n\n",
 
xml_error_string(xml_get_error_code($xml_parser)),
 
xml_get_current_line_number($xml_parser)));
 }
 } 
xml_parser_free($xml_parser);
 
?>
Could anybody tell me what I would have to change this to?
Reply With Quote
  #2 (permalink)  
Old 01-01-05, 03:32 AM
cardesign cardesign is offline
Newbie Coder
 
Join Date: Mar 2004
Location: UK
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
................
Reply With Quote
  #3 (permalink)  
Old 01-02-05, 03:59 AM
cardesign cardesign is offline
Newbie Coder
 
Join Date: Mar 2004
Location: UK
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Any ideas or thoughts, this is really urgent for my client.
Reply With Quote
Reply

Bookmarks


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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
md5 returns differnt results on linux/win Acecool PHP 1 10-01-04 08:50 AM
Displaying images from a XML feed 101 PHP 1 07-30-04 10:10 PM
javascripting and XML Christoff JavaScript 1 06-23-04 05:44 AM
PHP, MySQL Beginner... Help Needed Displaying Results db3db3 PHP 1 05-12-04 01:24 AM
posting of results script Sir-ihlatrebon Script Requests 0 02-17-04 11:46 AM


All times are GMT -5. The time now is 05:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.