0

It was a while that I use the function file_get_contents to get html data from a website. but today it dosen't, to see why I've used :

$html = @file_get_contents('http://www.thewebsite.com/');
if(!$html)
   exit( "Oops. Error :)" );    

And this show me the error message. So perhaps they have prevent somehow the connection.

Please masters how could I force the function to get the contents ?

EDIT :

This give this error :

Warning: file_get_contents(http://www.thewebsite.com/) 
       [<a href='function.file-get-contents'>function.file-get-contents</a>]: 
       failed to open stream: HTTP request failed! 

PS I've tried another website and this works fine

Sami El Hilali
  • 981
  • 3
  • 12
  • 21

2 Answers2

2
  1. Remove warning suppression
  2. Turn on error reporting
  3. Check the messages in error_log You should see detailed error message instead of "Oops. Error." Then you will know why it doesn't work
  • Then try to google error message. http://stackoverflow.com/questions/697472/file-get-contents-returning-failed-to-open-stream-http-request-failed – peter.svintsitskiy Feb 28 '13 at 10:59
0

According to manual page . A URL can be used as a filename with this function if the fopen wrappers have been enabled. Did you really check if every url return false and gave error. Then obviously you need to check settings.

kuldeep.kamboj
  • 2,566
  • 3
  • 26
  • 63