Your browser does not seem to support CSS. If images appear below, please disregard them.
toggle
May
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Sponsored Links
Latest Postings
Topic Options
Rate This Topic
#19256 - 01/21/03 12:06 PM help a newbie please
Joined: Mar 2002
Posts: 192
xero Offline
Member
xero Offline
Member

Joined: Mar 2002
Posts: 192
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


"Most of our imports come from outside the country" -George W. Bush

http://www.zero-technologies.com
Top
Sponsored Links
#19257 - 01/21/03 02:48 PM Re: help a newbie please
Joined: Mar 2002
Posts: 1,273
SilentRage Offline
DollarDNS Owner
SilentRage Offline
DollarDNS Owner

Joined: Mar 2002
Posts: 1,273
OH, USA
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.


Domain Registration, Hosting, Management
http://www.dollardns.net
Top
#19258 - 01/21/03 04:45 PM Re: help a newbie please
Joined: Oct 2002
Posts: 955
jonconley Offline
UGN Super Poster
jonconley Offline
UGN Super Poster

Joined: Oct 2002
Posts: 955
Merrill, IA, USA
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.

Top
#19259 - 01/21/03 05:35 PM Re: help a newbie please
Joined: Mar 2002
Posts: 536
Deviation187 Offline
Member
Deviation187 Offline
Member

Joined: Mar 2002
Posts: 536
L.A Cal.
lol id give him another couple of hours.. hes still sleeping


"Hmm, they have the internet on computers now." - Homer Simpson
http://wired.promodtecnologies.com/
Top
#19260 - 01/21/03 08:55 PM Re: help a newbie please
Joined: Mar 2002
Posts: 192
xero Offline
Member
xero Offline
Member

Joined: Mar 2002
Posts: 192
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?


"Most of our imports come from outside the country" -George W. Bush

http://www.zero-technologies.com
Top

Member Spotlight
Gremelin

Gremelin
Portland, OR; USA
Posts: 7,194
Joined: February 2002
Show All Member Profiles 
Forum Statistics
Forums46
Topics45,704
Posts80,872
Members2,157
Most Online1,567
Apr 25th, 2010
Top Posters(All Time)
UGN Security 38,868
Gremelin 7,194
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Newest Members
Herbert_Sherbert, codemauve, Lillysdragon1984, Brewwit, boa
2157 Registered Users
Who's Online Now
0 registered members (), 0 guests and 2 spiders.
Latest News