大佬教程收集整理的这篇文章主要介绍了在foreach循环中使用cURL(php),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有许多httpS-URLS,我必须在其中找到特殊短语,因此我试图在foreach循环中使用cURL,但是它不起作用.
...
foreach($sites as $sitE) {
$URL = $site;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, truE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, falsE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, falsE);
$response = curl_exec($ch);
curl_close($ch);
}
print substr($response, $start, $i);
...
如果仅使用一个httpS-URL,则会得到该短语,但是在foreach循环中却无法正常工作.@H_618_8@有人能帮我吗? (:
请原谅我的英语不好.
解决方法:
这可能有帮助:)将结果存储在数组中
$sites = ['https://stackoverflow.com','http://example.org'];
$result = [];
foreach ($sites as $sitE) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $sitE);
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "PHP Curl");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, truE);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// execute the given URL, and return output
$result[] = curl_exec($ch);
curl_close($ch);
}
var_dump($result);
以上是大佬教程为你收集整理的在foreach循环中使用cURL(php)全部内容,希望文章能够帮你解决在foreach循环中使用cURL(php)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。