簡體   English   中英

如何將圖形數據存儲在php變量中?

[英]How to store graph data in a php variable?

我正在嘗試獲取網站上特定頁面的喜歡次數並將其存儲在數組中。 卡在中間,我發現可以通過以下代碼獲得喜歡的次數以及其他數據:

/*$site="http://graph.facebook.com/?ids=http%3a%2f%2xxxxxxxx.com/abc.php";
$graph= file_get_contents($site);

輸出如下:

{"http:\/\/xxxxxxxx.com\/abc.php":{"id":"http:\/\/xxxxxxxx.com\/abc.php","shares":75,"comments":3}}

有沒有辦法我可以只存儲喜歡的數量,即在這種情況下,在php數組中是75?

我嘗試了explode(); 但問題是我將要使用的url的長度是恆定的。

這是一個json字符串將其解碼,使用json_decode您將獲得輸出作為數組。 參考: http : //php.net/manual/zh/function.json-decode.php

$array  = json_deocde($json_string, true);

echo "<pre>";
print_r($array);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM