Home > Article > Backend Development > file_get_contents Get remote web page content function_PHP tutorial
For some reason, the allow_url_fopen option of PHP is turned off, so file_get_contents cannot be used directly to obtain the content of the remote web page. That is, you can use another function curl.
Unlimited file_get_contents function to obtain remote web page content
function vita_get_url_content($url) {
if(function_exists('file_get_contents')) {
$file_contents = file_get_contents($url);
} else {
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, curlopt_url, $url);
curl_setopt ($ch, curlopt_returntransfer, 1);
curl_setopt ($ch, curlopt_connecttimeout, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
/*
For some reason, the allow_url_fopen option in the PHP tutorial is turned off, so file_get_contents cannot be used directly to obtain the content of the remote web page. That is, you can use another function curl.