Some host service providers put PHP allow_url_fopen option is off, just can't use file_get_contents directly to get the content of remote Web pages. That is, you can use another function curl.
Here are the different ways to file_get_contents and curl two functions
Example of using the File_get_contents function:
< ?php
$file_contents = file_get_contents('http://www.ccvita.com/');
echo $file_contents;
?>
To use an example of a curl function:
< ?php
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, 'http://www.ccvita.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>
Using the Function_exists function to determine whether PHP supports a function can easily write the following function
< ?php
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;
}
?>
In fact, this function is still open to question, if your host service provider to the file_get_contents and curl are closed, the above function will appear errors.