$url = "https://graph.facebook.com/fql?q=SELECT%20uid2%20FROM%20friend%20WHERE%20uid1=me()&access_token=sadfasdf";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$string = curl_exec($ch); // grab URL and pass it to the browser
echo $string;
curl_close($ch);
现在,echo $string
将抓取的整个数据输出为纯文本。
{ "data": [
{ "uid2": "91298391" },
{ "uid2": "00291509" },
{ "uid2": "101927261" }
]}
我怎样才能获取类似于 JSON 的特定数据?在这种情况下,我希望能够获取每个 ID。我有一种我会使用的感觉,preg_match
但我很难过。