Equivalent function for file_get_contents()?

oopbase picture oopbase · Jan 11, 2011 · Viewed 15.2k times · Source

I want to parse some information out of a html page. Currently I solve the problem like this:

header("Content-type: text/plain");    
$this->pageSource = file_get_contents ($this->page);
header("Content-type: text/html");

$this->page is the url of the website. This works fine on XAMPP, but when I upload my script on my webserver, I get the following error message:

Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0

So obviously I am not allowed to execute that function on my webserver.

So is there an equivalent function to solve my problem?

Answer

ajreal picture ajreal · Jan 11, 2011

Actually the function file_get_contents is not disabled,
but allow_url_fopen is disabled

you can replace it with curl

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$this->pageSource = curl_exec($ch);
curl_close($ch);

However, if you server block outgoing traffic, curl does not help too