[英]How to pass cURL result to variable
Hi all I need help regarding cURL, I'm new to using cURL in PHP so I want to ask this. 大家好,我需要有关cURL的帮助,我是PHP中使用cURL的新手,所以我想问这个。
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $get_url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$variable = curl_exec($curl);
$variable's value is boolean while cURL echoes a string during execution. 当cURL在执行期间回显字符串时,$ variable的值为boolean。 Is there anyway I could get that echoed string pass to a variable?
无论如何,我可以将回显的字符串传递给变量吗?
Thanks in advance 提前致谢
Set the option curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
设置选项
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
to return the result as a string, in your case the string will be stored in $variable
. 以字符串形式返回结果,在这种情况下,该字符串将存储在
$variable
。 Then, pass $variable
to whatever function you desire. 然后,将
$variable
传递给所需的任何函数。
Another solution is this way: 另一个解决方案是这样的:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $get_url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
ob_start();
curl_exec($curl);
$variable = ob_get_clean();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.