Hello, I purchased a site a while back which used an RSS reader to get content, now the site is reading an error Could not open RSS source "http://news.search.yahoo.com/news/rss?p=family+tree&ei=UTF-8". now coding is listed below, if possible could someone please tell me whats wrong, i'm assuming yahoo have changed their site slightly but any help would be fantastic, thanks in advance <?php $rss_url = "http://news.search.yahoo.com/news/rss?p=".$kword."&ei=UTF-8"; function rss_start_element($parser, $name, $attributes) { global $rss; $rss->start_element($parser, $name, $attributes); } function rss_end_element($parser, $name) { global $rss; $rss->end_element($parser, $name); } function rss_character_data($parser, $data) { global $rss; $rss->character_data($parser, $data); } class rss_parser { function rss_parser() { $this->error = ''; $this->file = ''; $this->channel = array(); $this->data = ''; $this->stack = array(); $this->num_items = 0; $this->xml_parser = xml_parser_create(); xml_set_element_handler($this->xml_parser, "rss_start_element", "rss_end_element"); xml_set_character_data_handler($this->xml_parser, "rss_character_data"); } function character_data($parser, $data) { if (empty($this->data)) $this->data = trim($data); // concatenate non-parsed data... else $this->data .= ' '.trim($data);// and get rid of white space. } function start_element($parser, $name, $attrs) { switch($name) { case 'RSS': break; case 'CHANNEL': break; case 'IMAGE': array_push($this->stack, $name); break; case 'ITEM': array_push($this->stack, $name); array_push($this->stack, $this->num_items); // push item index. $this->item[$this->num_items] = array(); $this->num_items++; break; case 'TEXTINPUT': array_push($this->stack, $name); break; default: array_push($this->stack, $name); break; } } function end_element($parser, $name) { switch ($name) { case 'RSS': break; case 'CHANNEL': break; case 'IMAGE': array_pop($this->stack); break; case 'ITEM': array_pop($this->stack); array_pop($this->stack); break; case 'TEXTINPUT': array_pop($this->stack); break; default: // child element. $element = (implode("']['",$this->stack)); eval("\$this->channel['$element']=\$this->data;"); // this does all the hard work. array_pop($this->stack); $this->data = ''; break; } } function parse() { if (!($fp = @fopen($this->file, "r"))) { $this->error = "Could not open RSS source \"$this->file\"."; return false; } while ($data = fread($fp, 4096)) { if (!xml_parse($this->xml_parser, $data, feof($fp))) { $this->error = sprintf("XML error: %s at line %d.", xml_error_string(xml_get_error_code($this->xml_parser)), xml_get_current_line_number($this->xml_parser)); return false; } } xml_parser_free($this->xml_parser); return true; } } $rss = new rss_parser(); $rss->file = $rss_url; $rss->parse() or die($rss->error); if ($rss->error) print $rss->error; $am = count($rss->channel["ITEM"]); for($x=0;$x<=$am;$x++) { $Title = $rss->channel["ITEM"][$x]["TITLE"]; $Link = $rss->channel["ITEM"][$x]["LINK"]; $Description = $rss->channel["ITEM"][$x]["DESCRIPTION"]; $html_ .= "<b><a href=\"".$Link."\">".$Title."</a></b><br />".$Description."<br /><br />"; } $RSSFeed = $html_; ?> PHP:
Hello, It can't read the URL using fopen either because allow_url_fopen is disabled in the PHP settings or if your using your localhost, it might be that your firewall is blocking PHP. If you can, then change the PHP settings/unblock. But if you are on a shared host, they might have curl installed so you could make it use that instead. Sky22
hey, thanks for reply just been out came back and seems to be fixed, not sure what problem was but seems to have resolved its self i thought it might have been a problem yahoo's end however i was able to manually access it maybe it was a problem with my server end, well at least i know its not the coding, thanks for help anyways
ok change that it is still a problem, think it was my cache telling me otherwise checked php settings on hosting server(shared), and allow_url_fopen is on both local and master so i have no idea what could be wrong? curl is enabled aswell so could try changing it to that but i've got no experience coding in php, is it a major change?
When there is a problem, go back to basic... What I would do is just set up a single php page with something like : <?php $capturedhtml = file_get_contents("http://www.google.com"); echo($capturedhtml); ?> If it doesn't work, then it means that there is a problem on your server with the metho "file_get_contents". I would just contact the hosting company then. If they have good support, they will repair this. If it does work, then it means it's a problem with this specific URL. Try : <?php $capturedhtml = file_get_contents("http://news.search.yahoo.com/news/rss?p=family+tree&ei=UTF-8"); echo($capturedhtml); ?> If it's not working, it's either a weird response (maybe in the header, I don't know) from yahoo's server or your web server is preventing websites to access this page for some reasons (a firewall ?). If the reading of google was working but not yahoo, try with another page on yahoo (like the home page). If it still doesn't work, then it's your hosting company that prenvents people to access yahoo domain's name, or yahoo is just ignoring requests from your webserver (it could happen if somebody using your hosting company abused some yahoo's service)...