【问题标题】:Save cURL Display Output String in Variable PHP在变量 PHP 中保存 cURL 显示输出字符串
【发布时间】:2013-08-14 17:36:44
【问题描述】:

他们可以选择将 curl 请求的输出保存在 php 变量中吗?

因为如果我只保存 $result 我得到 1 或什么都没有

<?php
$url='http://icanhazip.com';
$proxy=file ('proxy.txt');
$useragent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';

for($x=0;$x<count($proxy);$x++)
{
$ch = curl_init();
//you might need to set some cookie details up (depending on the site)
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_URL,$url); //set the url we want to use
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_PROXY, $proxy[$x]);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //set our user agent
$result= curl_exec ($ch); //execute and get the results
print $result; //display the reuslt
$datenbank = "proxy_work.txt"; 
$datei = fopen($datenbank,"a");
fwrite($datei, $result);  
fwrite ($datei,"\r\n"); 
curl_close ($ch);
}
?>

【问题讨论】:

  • here中搜索“CURLOPT_RETURNTRANSFER”。

标签: php variables curl output


【解决方案1】:

您需要将CURLOPT_RETURNTRANSFER 选项设置为true。

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

【讨论】:

    【解决方案2】:

    你需要添加一个curl选项的设置CURLOPT_RETURNTRANSFER:

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    这样可以避免输出,让程序继续运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-14
      • 2020-11-26
      • 1970-01-01
      • 2014-05-05
      相关资源
      最近更新 更多