【发布时间】:2018-02-13 22:22:04
【问题描述】:
这是我的代码。 我想为 $new_ch[] 修改 $new_ch。 curl_init() 这个函数是否可行?我想要一个为每个 $new_ch 自动递增的数组,以便我对带有 curl_init() 这个函数的数组感到好奇。祝你回复。谢谢。
<?php
$count = 0;
$judge = fopen($sourcefile,"r+");
while(!feof($judge))
{
$destination = fgets($judge);
$new_ch = curl_init();
curl_setopt($new_ch, CURLOPT_URL, $destination);
curl_setopt($new_ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($new_ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($new_ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($new_ch, CURLOPT_TIMEOUT, 30);
curl_setopt($new_ch, CURLOPT_USERAGENT, $agent_name);
curl_setopt($new_ch, CURLOPT_COOKIEFILE, $cookie_jar);
$getinner = curl_exec($new_ch);
$saveinner = fopen('./'.$datetime.'/'.$datetime.'.txt',"w+");
fwrite($saveinner,$getinner);
fclose($saveinner);
$dom_new = file_get_html('./'.$datetime.'/'.$datetime.'.txt');
foreach($dom_new->find('a') as $dom_new_element)
{
$needle_new = $dom_new_element->href;
$final_target = preg_match("/txt/",$needle_new);
$final_source = $site_rid.$needle_new."\n";
$mytrimaddress = parse_url($final_source, PHP_URL_QUERY);
$eachone = explode("&", $mytrimaddress);
$trimthename = trim($eachone[5]);
$lefttrim = ltrim($trimthename, "/");
$remaintrim = substr($lefttrim, 0, strlen($lefttrim)-1);
file_put_contents('./'.$datetime.'/'.$remaintrim, $final_source);
}
curl_close($new_ch);
$count++;
if($count > 5)
{
exit;
} else {
continue;
}
}
?>
编辑: 在过去的时刻,我不确定这种方式可以这样做。所以,我问了这个问题。我在互联网上搜索的大多数命令案例都分配给了一个变量而不是一个数组。
我希望为这些帖子增加一些投票。我也喜欢帮助别人的问题。但是,目前的声誉很低,我无法回答任何问题。希望你能理解我的表白。
【问题讨论】:
-
您的问题非常不清楚且难以理解。
-
你为什么不尝试一下,当它不起作用时回来显示你的损坏代码。
-
您好,您需要了解的模糊部分在哪里?我想修改。
-
“curl_init() 的变量数组”是什么意思?
curl_init()在成功时返回 cURL 句柄,在错误时返回 false。像已经提到的其他人一样,如果您有一些特定问题,请尝试并回来。 -
@MagnusEriksson 谢谢。