解析错误:语法错误,意外'[',期待')',可能是PHP版本问题

时间:2015-11-17 15:53:55

标签: php api object instagram

我的代码出错了。我知道现在它与php版本有关。但是我应该更改我的代码以使其正常工作?

$json = file_get_contents(
'https://api.instagram.com/v1/users/'. $user_id .'/media/recent/?client_id=' . $client_id . '&count=' . $count);

$decode = json_decode($json, true);
$output = '';

$func = function($post['tags']){ 
    $i=0; 
    while(!empty($post['tags'])){ 
        return $post['tags'][$i]." ";
        $i++;
    }
};

foreach ($decode['data'] as $post) {
    $output .= $modx->getChunk($tpl,
        array(
            'link'      => $post['link']
            ,'image'     => $post['images']['standard_resolution']['url']
            ,'likes'     => $post['likes']['count']
            ,'hashtags'  => $func
        )
    );
}

return $output;

由于

1 个答案:

答案 0 :(得分:0)

错误是您将$post['tags']传递给函数声明。你可以改变

$func = function($post['tags'])
...

$func = function($tags) {
    $i=0; 
    while(!empty($tags)){ 
        return $tags[$i]." ";
        $i++;
    }
}

并将其称为

$func($post['tags'])