Home > Article > Backend Development > PHP curl CURLOPT_RETURNTRANSFER parameter usage examples, curl examples_PHP tutorial
Get the page content, do not output it directly to the page, CURLOPT_RETURNTRANSFER parameter setting
Use PHP curl to obtain page content or submit data. Sometimes you want the returned content to be stored as a variable instead of output directly. At this time, you must set curl's CURLOPT_RETURNTRANSFER option to 1 or true.
1. Curl gets the page content and outputs it directly. Example:
$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 gets the page content without outputting it directly. Example:
$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 obtained but has not been output to the page.
curl_close($ch);
echo $response;
?>