Get page content, not output directly to page, curlopt_returntransfer parameter settings
Using PHP curl to get page content or submit data, sometimes you want the returned content to be stored as a variable rather than as a direct output. This time it is necessary to set the Curl Curlopt_returntransfer option to 1 or true.
1, Curl get the page content, direct output Example:
Copy Code code as follows:
<?php
$url = ' http://www.jb51.net ';
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
curl_setopt ($ch, Curlopt_ssl_verifyhost, false);
Curl_exec ($ch);
Curl_close ($ch);
?>
2, Curl get the page content, not directly output examples:
Copy Code code as follows:
<?php
$url = ' http://www.jb51.net ';
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
curl_setopt ($ch, Curlopt_ssl_verifyhost, false);
curl_setopt ($ch, Curlopt_returntransfer, 1);
$response = curl_exec ($ch); The content has been fetched and has not been printed on the page.
Curl_close ($ch);
Echo $response;
?>