2013-05-06 30 views
0

跳過500個響應事情是這樣的......我通過一個foreach循環運行一串網址的。每個URL都將通過fil_get_contents()傳遞,但有些會返回500個錯誤(預期),我想跳過/忽略返回的500個錯誤,但仍然爲有效響應提取數據。我有這個設置,但仍然在這500個響應中出現未定義索引的錯誤。從循環的file_get_contents

foreach($a['response']['groups']['users']['name'] as $key => $values) 
    { 
    $id = $values['uname']['id']; 
    $url = "http://thisurlimusing.com"."$id"; 
    $context = stream_context_create(array('http' => array('ignore_errors' => true),)); 
    $string = file_get_contents($url,false,$context); 
    $array = json_decode($string, true); 
    print_r($array['specific']);   
    } 

回答

0

你的麻煩是由設置在trueignore_errors(HTTP)引起的。在這種情況下,file_get_contents將返回錯誤響應文本。

以下行會的工作:

$string = file_get_contents($url,false); 
if ($string !== FALSE) { 
    $array = json_decode($string, true); 
}