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:
and the php code im using to add the xml news feeds is:
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
Code
Fatal error: Cannot redeclare untag() (previously declared
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; ?>