quickstopman Posted January 31, 2008 Share Posted January 31, 2008 hi guys i currently have a script that grabs RSS feeds my one problem is that for the layout im using i need to while() the function multiple times, and i always get this error Fatal error: Cannot redeclare startelement() (previously declared in /home/pokebash/public_html/socialgrabbr/rss_grabbr.php:15) in /home/pokebash/public_html/socialgrabbr/rss_grabbr.php on line 15 here is the function script: function grabRSS($feed_url) { $insideitem = false; $tag = ""; $title = ""; $description = ""; $link = ""; function startElement($parser, $name, $attrs) { global $insideitem, $tag, $title, $description, $link; if ($insideitem) { $tag = $name; } elseif ($name == "ITEM") { $insideitem = true; } } function endElement($parser, $name) { global $insideitem, $tag, $title, $description, $link; if ($name == "ITEM") { echo "<p align='left'>"; printf("<dt><b><a href='%s'>%s</a></b></dt>", trim($link),htmlspecialchars(trim($title))); printf("<dd>%s</dd>", $description); echo "</p><br><br>"; $title = ""; $description = ""; $link = ""; $insideitem = false; } } function characterData($parser, $data) { global $insideitem, $tag, $title, $description, $link; if ($insideitem) { switch ($tag) { case "TITLE": $title .= $data; break; case "DESCRIPTION": $description .= $data; break; case "LINK": $link .= $data; break; } } } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); $fp = fopen($feed_url,"r") or die("Error reading RSS data."); while ($data = fread($fp, 4096)) xml_parse($xml_parser, $data, feof($fp)) or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); fclose($fp); xml_parser_free($xml_parser); } any ideas or alternatives? Quote Link to comment https://forums.phpfreaks.com/topic/88752-solved-how-to-use-this-function-more-than-once/ Share on other sites More sharing options...
cooldude832 Posted January 31, 2008 Share Posted January 31, 2008 the error is that you didn't close your first function grabRSS() it is lookign like you trying to do some OOP style stuff, if so then look at the OOP subboard Quote Link to comment https://forums.phpfreaks.com/topic/88752-solved-how-to-use-this-function-more-than-once/#findComment-454551 Share on other sites More sharing options...
quickstopman Posted January 31, 2008 Author Share Posted January 31, 2008 no i ended the function im confused about why its not letting me declare the functions more than once Quote Link to comment https://forums.phpfreaks.com/topic/88752-solved-how-to-use-this-function-more-than-once/#findComment-454560 Share on other sites More sharing options...
cooldude832 Posted January 31, 2008 Share Posted January 31, 2008 because a function an only be declared once you declare by saying <?php function do_some_stuff(){ } do_some_stuff(); do_some_stuff(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88752-solved-how-to-use-this-function-more-than-once/#findComment-454562 Share on other sites More sharing options...
quickstopman Posted January 31, 2008 Author Share Posted January 31, 2008 ok i figured out what i had to do, i just removed all the inner functions out side of the grabRSS() and it works now thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/88752-solved-how-to-use-this-function-more-than-once/#findComment-454566 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.