Using file_get_contents to crawl the content of the page is not successful, perhaps because some host services to the PHP allow_url_fopen option is closed, is unable to directly use file_get_contents to get the content of the remote Web page. That is, you can use another function, curl.
Here are the different ways to do the same function for file_get_contents and curl two functions
Example of using the File_get_contents function:
Copy CodeThe code is as follows:
< PHP
$file _contents = file_get_contents (' http://www.jb51.net ');
echo $file _contents;
?>
Use an example of a curl function:
Copy CodeThe code is as follows:
< PHP
$ch = Curl_init ();
$timeout = 5;
curl_setopt ($ch, Curlopt_url, ' http://www.jb51.net ');
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
$file _contents = curl_exec ($ch);
Curl_close ($ch);
echo $file _contents;
?>
http://www.bkjia.com/PHPjc/327841.html www.bkjia.com true http://www.bkjia.com/PHPjc/327841.html techarticle use file_get_contents to crawl page content is not successful, perhaps because some host service provider to PHP allow_url_fopen option is closed, is unable to directly use file_get_contents to get ...