In-depth analysis of the reasons why the file_get_contents function fails to capture content_PHP tutorial

WBOY
Release: 2016-07-21 15:03:22
Original
800 people have browsed it

Using file_get_contents to capture the page content is unsuccessful. It may be because some hosting service providers have turned off the allow_url_fopen option of PHP, which means that file_get_contents cannot be used directly to obtain the content of the remote web page. That is, you can use another function curl.
The following are different ways of writing the same function of the file_get_contents and curl functions
Example of using the file_get_contents function:

Copy the code The code is as follows:

< ?php
$file_contents = file_get_contents('http://www.jb51.net');
echo $file_contents;
?>

Example of using curl function:
Copy code The 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;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327841.htmlTechArticleUsing file_get_contents to capture the page content failed, maybe because some hosting service providers turned off the allow_url_fopen option of php , but you can’t use file_get_contents directly to get it...
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