Home  >  Article  >  Backend Development  >  PHP obtains detailed explanation of web pages through cURl library function_PHP tutorial

PHP obtains detailed explanation of web pages through cURl library function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:38:44722browse

I recently worked on a small project that used the cURl library function. I found some information from the Internet, referred to a foreign blog and official manual, and summarized it.
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page Return to web page
CURLOPT_HEADER => false, // Do not return header information
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // Set UserAgent
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect connection timeout
CURLOPT_TIMEOUT => 120, // timeout on response reply timeout
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header[errno] = $err;
$header[errmsg] = $errmsg;
$header[content] = $content;
return $header;
}
Original English text:
http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486456.htmlTechArticleI recently did a small project using the cURl library function. I found some information from the Internet and referred to a foreign blog and official website. Manual, to summarize. function get_web_page( $url ) { $options = array( CU...
Statement:
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