|
|
|
|
|
|
#19256 - 01/21/03 07:06 AM
help a newbie please
|
Member
Registered: 03/28/02
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: Fatal error: Cannot redeclare untag() (previously declared and the php code im using to add the xml news feeds is: <?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
|
|
Top
|
|
|
|
Sponsored Links
Sponsor 
|
Sponsor Advertisements help keep UGN Security Online.
Support UGN Security by Purchasing our Sponsors Products.
|
| Top |
|
|
|
#19260 - 01/21/03 03:55 PM
Re: help a newbie please
|
Member
Registered: 03/28/02
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?
|
|
Top
|
|
|
|
|
Registered: 02/11/08
Posts: 16
|
|
6890 Members
44 Forums
11065 Topics
45844 Posts
Max Online: 677 @ 06/30/07 10:06 PM
|
|
|
1 registered (Gizmo),
13
Guests and
3
Spiders online. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|