在 foreach 循环中使用 cURL (php)

Using cURL in a foreach-loop (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 循环中它不起作用。 有人能帮我吗? (:

请原谅我糟糕的英语..

这可能会有所帮助 :) 将结果存储在数组中

$sites = ['https://whosebug.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);