There is a parameter in CURL CURLOPT_RETURNTRANSFER: This parameter returns the information obtained by curl_exec() in the form of a file stream instead of outputting it directly. For example: The function of the CURLOPT_RETURNTRANSFER parameter is to
assign the content obtained by CRUL to a variable. It defaults to 0 and directly returns the text stream of the obtained output. Sometimes, it would not be good if we want to use the return value for judgment or other purposes. Therefore, sometimes we want the returned content to be stored in variables instead of being output directly, so what should we do? This article mainly introduces the method of
php curl_exec() function CURL to obtain the return valueIn fact, CURLOPT_RETURNTRANSFER can be set. If it is set to CURLOPT_RETURNTRANSFER 1, it will use PHP curl to obtain the page content or Submit data and store it as a variable instead of outputting it directly.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Let’s look at two examples below,
1. Curl gets the page content and directly outputs the example:<?php
$url = 'http://www.php.cn';
$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);
?>
1. The above is the detailed content of php curl_exec() function CURL method to get the return value. For more information, please follow other related articles on the PHP Chinese website!<?php
$url = 'http://www.php.cn';
$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); // 已经获取到内容,没有输出到页面上。
curl_close($ch);
echo $response;
?>