2013-08-13 12 views
14

ist ihre eine Option, um den Outout einer Curl-Anfrage in einer PHP-Variable zu speichern?Speichern cURL Anzeige Ausgabe String in Variable PHP

Denn wenn ich nur das $ result speichern erhalte ich eine 1 oder nichts

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

Suchen Sie "CURLOPT_RETURNTRANSFER" in [hier] (http://www.php.net/manual/en/function.curl-setopt.php). – Passerby

Antwort

24

Sie müssen CURLOPT_RETURNTRANSFER Option auf true setzen.

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
+0

Thx das funktioniert so, wie ich es erwarte. –

1

Sie benötigen eine Einstellung von curl Option CURLOPT_RETURNTRANSFER hinzuzufügen:

curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);

Damit können Sie die Ausgabe vermeiden und das Programm weiterlaufen lassen.