2013-08-13 36 views
14

là tùy chọn của chúng để lưu phần xuất của yêu cầu curl trong biến php?Lưu chuỗi đầu ra hiển thị cURL trong biến PHP

Bởi vì nếu tôi chỉ lưu kết quả $ i có được một 1 hoặc không có gì

<?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

Tìm kiếm "CURLOPT_RETURNTRANSFER" trong [đây] (http://www.php.net/manual/en/function.curl-setopt.php). – Passerby

Trả lời

24

Bạn cần phải thiết lập CURLOPT_RETURNTRANSFER tùy chọn là true.

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

Thx hoạt động như tôi mong đợi. –

1

Bạn cần phải thêm một thiết lập tùy chọn CURLOPT_RETURNTRANSFER curl:

curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);

Với điều này, bạn có thể tránh đầu ra và làm cho chương trình tiếp tục chạy.

Các vấn đề liên quan