UGN Security
Posted By: xero help a newbie please - 01/21/03 12:06 PM
ok hi, im working on my site, and im trying to add xml news feeds. it works fine when i only have one, but when i wanna get feeds from multiple sources on one page, it gives me error:

Code
 Fatal error: Cannot redeclare untag() (previously declared  
and the php code im using to add the xml news feeds is:

Code
 <?php
$feed = 'http://www.computerworld.com/news/xml/0,5000,73,00.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";

	preg_match_all($preg, $string, $tags);
	foreach ($tags[1] as $tmpcont){
		$tmpval[] = $tmpcont;
	}
	return $tmpval;
}
$items = untag($xml, 'item');

$html = '

';
foreach ($items as $item) {
	$title = untag($item, 'title');
	$link = untag($item, 'link');

	$html .= '<a href="' . $link[0] . '">' . $title[0] . "</a>
\n";
}
$html .= '';

echo $html;
?> 
i have other feeds as well, so i just simply copy and pasted that same code, pasted again and changed the url of the xml. obviously this isnt the way i should be doing it. can anyone help? im really new at this php stuff :p
Posted By: SilentRage Re: help a newbie please - 01/21/03 02:48 PM
The error means that you have 2 functions called 'untag'. I see only 1 untag function in your code however. So are you loading in any code from other files that has an untag function in it? Cause that would hurt ya.
Posted By: jonconley Re: help a newbie please - 01/21/03 04:45 PM
Did you get my PM?

I think he is running all that code separately for each URL. He could add a loop that will go through each URL or simply remove the calls to function where it occurs later on I believe.
Posted By: Deviation187 Re: help a newbie please - 01/21/03 05:35 PM
lol id give him another couple of hours.. hes still sleeping
Posted By: xero Re: help a newbie please - 01/21/03 08:55 PM
Yeah, i got the pm, and i agree its not liking the fact that i just copy and pasted the same code lol.. But how would i would i use one piece of code? like say i wanted to get the feed from http://www.blabla.com/1.xml and another one from http://www.blabla.com/2.xml? how would i have to chnage the php to do so? oh and silentrage, yer right, im just copying that same code and pasting it again, changing the url and it is hurting me heh.. how will i use a loop to use only one code for multiple feeds?
© UGN Security Forum