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?
The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string.
Description ¶ This function is similar to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to length bytes. On failure, file_get_contents() will return false . file_get_contents() is the preferred way to read the contents of a file into a string.
The file_get_contents() function reads a file into a string. The file_put_contents() function writes data to a file.
readfile("/path/to/file"); This will read the file and send it to the browser in one command. This is essentially the same as: echo file_get_contents("/path/to/file");
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
Use curl()
.
cURL is the usual standard solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With