gpt4 book ai didi

php - 在变量 PHP 中保存 cURL 显示输出字符串

转载 作者:IT王子 更新时间:2023-10-29 00:16:47 25 4
gpt4 key购买 nike

他们是否可以选择将 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);
}
?>

最佳答案

你需要设置CURLOPT_RETURNTRANSFER选项为真。

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

关于php - 在变量 PHP 中保存 cURL 显示输出字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18203411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com