繁体   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