0

Here's the deal... I'm running a bunch of URL's through a foreach loop. Each URL will pass through fil_get_contents() but some will return 500 errors (expected), I want to skip/ignore any 500 errors, that are returned, but still pull the data for the valid responses. I have this setup, but still getting errors for undefined index on those 500 responses.

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']);        
    }
4

1 回答 1

0

您的问题是由ignore_errors(http) 设置为true. 在这种情况下,file_get_contents返回错误响应文本。

以下几行将起作用:

$string = file_get_contents($url,false);
if ($string !== FALSE) {
    $array =  json_decode($string, true);
}
于 2013-05-06T12:58:05.507 回答