保存cURL在变量PHP中显示输出字符串 [英] Save cURL Display Output String in Variable PHP

查看:178
本文介绍了保存cURL在变量PHP中显示输出字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是他们的保存curp请求outpout的一个选项在一个php变量?

is their an option to save the outpout of a curl request in a php variable?

因为如果我只保存$结果我得到一个1或没有

Because if i only save the $result i get a 1 or nothing

<?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);
}
?>


推荐答案

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

You need to set CURLOPT_RETURNTRANSFER option to true.

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

这篇关于保存cURL在变量PHP中显示输出字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆