2013-01-11 18 views
0

我想要統計一個URl的facebook總數,並將其保存在mysql中。使用php和FQL獲取facebook像count使用

即時通訊使用Facebook的FQL來計數。

代碼

https://api.facebook.com/method/fql.query?query=SELECT like_count FROM link_stat WHERE url="http://www.stackoverflow.com" 

此方法將返回我的XML文件具有以下

<fql_query_response list="true"><link_stat><like_count>1548</like_count></link_stat></fql_query_response> 

什麼,我想知道是怎麼只拿像數的刺痛。提前致謝。

回答

0

使用preg_match_all這個

$string = '<fql_query_response list="true"><link_stat><like_count>1548</like_count></link_stat></fql_query_response>'; 

preg_match_all("/(?P<number>\d+)/", $string, $matches); 

print_r($matches['number'][0]); 

注:考慮到還有沒有其他的號碼出現在字符串,如果有需要大家知道的結構發生改變slitly預浸比賽:)

0

在xml中,你可以使用SimpleXML。代碼應該是這樣的:

$xml = simplexml_load_string($your_facebook_response); 
$count = $xml->link_stat[0]->link_count[0]; 
相關問題