freephoneid Posted December 9, 2008 Share Posted December 9, 2008 Hi, I want to display RSS feed in a marquee ticker. Feed URL: http://www.wired.com/news/feeds/rss2/0,2610,,00.xml I'm trying to fetch contents using following command: $fp = fsockopen($host, $port, $errno, $errstr, 2) But, I'm getting error: "Failed to Get RSS Data An error was ecnountered attempting to get the RSS data: An unknown error occurred." Can any one help me how to fetch xml from this feed url? Can any one provide me the details? Thanks in Advance! Quote Link to comment Share on other sites More sharing options...
php.ajax.coder Posted December 9, 2008 Share Posted December 9, 2008 try this script http://www.w3schools.com/php/php_ajax_rss_reader.asp Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 9, 2008 Share Posted December 9, 2008 Do you have allow_url_open enabled? Quote Link to comment Share on other sites More sharing options...
freephoneid Posted December 9, 2008 Author Share Posted December 9, 2008 Thanks! I saw that article but I would like to know why the below connection is not happening? $host = "rss.news.yahoo.com"; $uri = "/rss/topstories"; $request = "GET " . $uri . " HTTP/1.0\r\n"; $request .= "Host: " . $host . "\r\n"; $request .= "Connection: close\r\n\r\n"; if( $http = fsockopen($host, 80, $errno, $errstr, 5) ) { ..... } Code gives error while opening socket....Can you please help? Thanks! Quote Link to comment Share on other sites More sharing options...
freephoneid Posted December 9, 2008 Author Share Posted December 9, 2008 Yes, I've checked & allow_url_open is On. But allow_url_include was Off, so I tried with that On as well but still no luck! Please help! Why the below code not working? $host = "rss.news.yahoo.com"; $uri = "/rss/topstories"; $request = "GET " . $uri . " HTTP/1.0\r\n"; $request .= "Host: " . $host . "\r\n"; $request .= "Connection: close\r\n\r\n"; if( $http = fsockopen($host, 80, $errno, $errstr, 5) ) { ..... } Quote Link to comment Share on other sites More sharing options...
freephoneid Posted December 9, 2008 Author Share Posted December 9, 2008 can any one try below code at yr end n see if it works? $host = "rss.news.yahoo.com"; $uri = "/rss/topstories"; $request = "GET " . $uri . " HTTP/1.0\r\n"; $request .= "Host: " . $host . "\r\n"; $request .= "Connection: close\r\n\r\n"; if( $http = fsockopen($host, 80, $errno, $errstr, 5) ) { echo "hurray.."; } Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 9, 2008 Share Posted December 9, 2008 It does here. Quote Link to comment Share on other sites More sharing options...
freephoneid Posted December 9, 2008 Author Share Posted December 9, 2008 strange.. why its not working for me? is it bcuz of proxy? can you pls help? Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 9, 2008 Share Posted December 9, 2008 I'm not sure. I'm always a bit uncomfortable with remote files. Could be something in php.ini. Could be something with your ISP... Got no idea. Also note, that while it displays "Hooray", it will timeout when I add $foo = fread($http,10); echo $foo; after that Quote Link to comment Share on other sites More sharing options...
freephoneid Posted December 9, 2008 Author Share Posted December 9, 2008 hmmm...so we shouldn't rely on fsockopen? Quote Link to comment Share on other sites More sharing options...
freephoneid Posted December 9, 2008 Author Share Posted December 9, 2008 okay....even the below code does not work for me? <?php $xml="http://news.google.com/news?ned=us&topic=h&output=rss"; $xmlDoc = new DOMDocument(); $xmlDoc->load($xml);//get elements from "<channel>" $channel=$xmlDoc->getElementsByTagName('channel')->item(0); $channel_title = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue; $channel_link = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue; $channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;//output elements from <channel>" echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>"); echo("<br />"); echo($channel_desc . "</p>");//get and output "<item>" elements $x=$xmlDoc->getElementsByTagName('item'); for ($i=0; $i<=2; $i++) { $item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue; echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br />"); echo ($item_desc . "</p>"); } ?> Gives error : failed to open stream: A connection attempt failed because the connected party did not properly respond .... Can any one help? Thanks! Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 9, 2008 Share Posted December 9, 2008 Try SimpleXML <?php $sxe = new SimpleXMLElement('http://news.google.com/news?ned=us&topic=h&output=rss', NULL, TRUE); echo $sxe->asXML(); ?> Quote Link to comment Share on other sites More sharing options...
freephoneid Posted December 9, 2008 Author Share Posted December 9, 2008 Nope......same error: SimpleXMLElement::__construct(http://news.google.com/news?ned=us&topic=h&output=rss) [<a href='function.SimpleXMLElement---construct'>function.SimpleXMLElement---construct</a>]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\r\n in C:\\aa.php on line 4 Please help! Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 9, 2008 Share Posted December 9, 2008 Apparently there is something forbidding you to open remote files. I know only about allow_url_fopen php.ini setting that could to this. Maybe it is indeed the proxy interfering... Quote Link to comment 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.