Google Answers Logo
View Question
 
Q: PHP Script for an XML news feed ( No Answer,   5 Comments )
Question  
Subject: PHP Script for an XML news feed
Category: Computers > Programming
Asked by: jordykoski-ga
List Price: $10.00
Posted: 08 Jul 2004 08:06 PDT
Expires: 09 Jul 2004 07:57 PDT
Question ID: 371302
I need a PHP script, that does not rely upon MySQL, to display an xml
news feed on my website. Here is the xml source:

http://asp.sriworld.com/xml/news/csrwire.cgi/csrwire.xml

I want to incorporate this xml news feed, in a fashion similar to the
website: www.cicr.net 

On my page, I do not want to display the whole news article, just the
headline that will also be a link to the article on the sriworld.com
website. When the headline is clicked on, one should be brought to the
article in a new window! I want to display the top three headlines on my site.

For clarification, I do not have MySQL so using this is not an option.
Answer  
There is no answer at this time.

Comments  
Subject: Re: PHP Script for an XML news feed
From: crythias-ga on 08 Jul 2004 18:01 PDT
 
This is pure plagiarism, from http://martin.f2o.org/php/xml-feed
Google search: XML feed PHP

I only changed some things to adjust for this nasty nasty 
<article id="2868"> thing that "untag" couldn't handle.
I leave it up to you to decide how to div or table tag this.
<?php
$feed = 'http://asp.sriworld.com/xml/news/csrwire.cgi/csrwire.xml';
ini_set('allow_url_fopen', true);
$fp = fopen($feed, 'r');
$xml = '';
while (!feof($fp)) {
$xml .= fread($fp, 128);
}
fclose($fp);

function untag($string, $tag) {
$tmpval = array();
$preg = "|<$tag>(.*?)</$tag>|s";
if ($tag=='article') {
$preg = "|<article .........>(.*?)</article>|s";
echo $preg;
}
preg_match_all($preg, $string, $tags);
foreach ($tags[1] as $tmpcont){
$tmpval[] = $tmpcont;
}
return $tmpval;
}

$items = untag($xml, 'article');
$max=count($items)-3;
echo $max;
$start=1;
$html = '';

for($i=$start;$i<$start+3;$i++){
$title = untag($items[$i], 'headline');
$link = untag($items[$i], 'url');
echo $title[1];
$html .= '<a href="' . $link[0] . '" title="' . $title[0] . '">';
$len=strlen($title[0]);
if($len>20){
$words=explode(' ',$title[0]);
$title[0]='';
for($w=0;$w<count($words);$w++){
$title[0] .= $words[$w] . ' ';
if(strlen($title[0])>20){
$title[0] .= '...';
break;
}
}
}
$html .= $title[0] . "</a><br />\n";
}
echo $html; 
?>
Subject: Re: PHP Script for an XML news feed
From: crythias-ga on 08 Jul 2004 18:03 PDT
 
darn it, I hate when I leave debugging stuff in there... Kindly remove
the echo $preg; and $echo max; lines...
Subject: Re: PHP Script for an XML news feed
From: crythias-ga on 08 Jul 2004 18:08 PDT
 
I don't really know how to keep it from breaking when your source
reaches 5 digits of articles. :(. All I can say is add another period
when it happens.
Subject: Re: PHP Script for an XML news feed
From: crythias-ga on 08 Jul 2004 20:46 PDT
 
sorry, also please remove echo $title[1];. I had a lot of problems
getting this to work, and when I finally had links to click, I
hurriedly posted without removing the debug information.
Subject: Re: PHP Script for an XML news feed
From: jordykoski-ga on 09 Jul 2004 07:56 PDT
 
great, thanks for the work. how do i pay the $10....i'm closing the question

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy