views:

49

answers:

4
$fp = fopen("http://feeds.reuters.com/Reuters/PoliticsNews?format=xml","r")
    or die("Error reading RSS data.");

The above coding working correctly in localhost;;;

but in server display "Error reading RSS data."...

i dont know why....

anybody please explain me...

i am waiting...

thanks

A: 

Its very likely that the server is configured so that fopen() can not open a remote URL. You might want to try Simplepie for parsing feeds, it takes the pain out of it.

Tim Post
+2  A: 

A possible reason could be that allow_url_fopen might be disabled (quoting) :

This option enables the URL-aware fopen wrappers that enable accessing URL object like files.

You can check using the phpinfo() function, to see if it's enabled or not.


If it's not enabled, you'll have to use another solution to send the HTTP request that fetches that remote content.

Using curl might be a solution, for instance ; see curl_exec for a quick example, and curl_setopt for a list of all possible options.
Here's what a simple request would look like, though :

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://feeds.reuters.com/Reuters/PoliticsNews?format=xml");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$feed = curl_exec($ch);
curl_close($ch);

This will get you the content of the feed in $feed -- but check the manual page of curl_setopt : there are so many options that going through the list cannot be a bad idea.


Still, as a precaution, before going this way, you might want to check if curl is enabled, is the output of phpinfo()...

Pascal MARTIN
+2  A: 

Try making sure that allow_url_fopen is enabled on the server. If it isn't, the call to fopen will fail.

Annath
A: 

rubbish talks of "possible reasons" and not a single suggestion how to get a real reason.

ini_set('display_errors',1);
error_reporting(E_ALL);

at the top of the script to see what goes wrong.

Col. Shrapnel
Umm.. rubbish? Yeah, that'll go far. ini_set() doesn't always work, btw :)
Tim Post
I'm not talking of "always". I'm talking of now. in *this* case it'll work, as we can see this code has no syntax errors.
Col. Shrapnel
if allow_url_fopen isn't enabled, there's a good chance ini_set() is listed in disable_functions. I fail to see how pointing the OP to phpinfo() and docs that describe allow_url_fopen is rubbish?
Tim Post
because it's guessing. programmer shouldn't guess. programmer should debug.
Col. Shrapnel