Equivalent function for file_get_contents ()?

I want to analyze some information from an html page. I am currently solving the problem as follows:

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 to my web server, the following error message appears:

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

Therefore, obviously, I am not allowed to perform this function on my web server.

So, is there an equivalent function to solve my problem?

+6
php file-get-contents
source share
5 answers

Actually the file_get_contents function is not disabled,
but allow_url_fopen 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 the server blocks outgoing traffic, curl also does not help.

+19
source share

Use curl() .

+4
source share

cURL is the usual standard solution.

+2
source share

Use curl and why do you need to change the title to plain text to extract data? This is not necessary if you are retrieving data.

0
source share

If you have a curl, use it for this perfectly.

 $urlx = 'http://yoururl'; $data="from=$from&to=$to&body=".urlencode($body)."&url=$url"; //set post parameters $process = curl_init($urlx); //init curl connection curl_setopt($process, CURLOPT_HEADER, 0); curl_setopt($process, CURLOPT_POSTFIELDS, $data); curl_setopt($process, CURLOPT_POST, 1); curl_setopt($process, CURLOPT_RETURNTRANSFER,1); curl_setopt($process,CURLOPT_CONNECTTIMEOUT,1); $resp = curl_exec($process); //your content curl_close($process);
$urlx = 'http://yoururl'; $data="from=$from&to=$to&body=".urlencode($body)."&url=$url"; //set post parameters $process = curl_init($urlx); //init curl connection curl_setopt($process, CURLOPT_HEADER, 0); curl_setopt($process, CURLOPT_POSTFIELDS, $data); curl_setopt($process, CURLOPT_POST, 1); curl_setopt($process, CURLOPT_RETURNTRANSFER,1); curl_setopt($process,CURLOPT_CONNECTTIMEOUT,1); $resp = curl_exec($process); //your content curl_close($process); 
0
source share

All Articles