phpinfo() Posted June 15, 2007 Share Posted June 15, 2007 Any tips on how I might update this to avoid using fopen? <?php $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") { printf("<dt><b><a href='%s' class='cyanText' target=_blank>%s</a></b></dt>", trim($link),htmlspecialchars(trim($title))); printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description))); $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("http://www.feed.com/rss/feed/index.xml","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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/55736-convert-code-fopen-to-curl/ Share on other sites More sharing options...
phpinfo() Posted June 18, 2007 Author Share Posted June 18, 2007 This basically pulls an RSS feed and displays it on your site. Quote Link to comment https://forums.phpfreaks.com/topic/55736-convert-code-fopen-to-curl/#findComment-276839 Share on other sites More sharing options...
per1os Posted June 18, 2007 Share Posted June 18, 2007 www.php.net/file_get_contents www.php.net/file Which ever you prefer a string or an array. Quote Link to comment https://forums.phpfreaks.com/topic/55736-convert-code-fopen-to-curl/#findComment-276841 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.