Home > Backend Development > PHP Tutorial > file_get_contents Get remote web page content function_PHP tutorial

file_get_contents Get remote web page content function_PHP tutorial

WBOY
Release: 2016-07-20 11:01:30
Original
1005 people have browsed it

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.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445436.htmlTechArticleFor some reason, the allow_url_fopen option of php is turned off, but file_get_contents cannot be used directly to obtain the remote web page. content. That is, you can use another function cu...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template