2012-02-04 20 views
0

我有一个使用JSON循环一些数据的函数。如何检查页面看起来为空时的Json或Curl?

的问题是,WEH n我的foreach循环在这里发现这种情况https://graph.facebook.com/search?q=berlusca&limit=10&type=post&until=1327422514它停止工作...

我如何检查,当页面有空白的数据?

这是我的foreach:

function getPostInfo($url, $lang, $stopwords) { 
$j = json_decode(startCurl($url)); 
foreach($j->data as $v) { 
if ($v->type == 'status') { 
     $post['author_id'][] = $v->from->id; 
     $post['original_id'][] = $v->id; 
     $ret['post_url'][] = getPostUrl($original_id, $author_id); 
     //$description = stopWords($v->message); 
     $post['description'][] = $v->message; 
     $post['pub_date'][] = $v->created_time; 
    } 
} 
return $post; 
} 
+0

是什么意思停止工作?你并没有初始化'$ post'。 – Vyktor 2012-02-04 20:53:33

回答

0
if (count($j->data) > 0) { 
    foreach ... 
} 
相关问题