0

次のコードを使用して、ページのいいねの数を取得しています。

        <?php
    $site="http://graph.facebook.com/?ids=http%3a%2f%2fXXXXXXXX/svce.php";
    $graph= file_get_contents($site);

    $json_string=$graph; 
    $array  = json_decode($json_string, true);

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

    $var = $array['shares'];
    echo $var;


    ?>

しかし、次のコードをエコーアウトしようとするたびに。私は常に次のような未確認のインデックス通知を取得します。

どこが間違っているのですか?

print_r の出力は次のとおりです。

 Array
(
     [http://xxxxxxxxx/svce.php] => Array

    (
        [id] => http://xxxxxxxxx/svce.php
        [shares] => 7
        [comments] => 3
     )

 )
4

2 に答える 2

1

前に、サイト名をキーとして使用する必要があります。

構造:

- http://example.com
  - id
  - shares

これは、PHPでは次のことを意味します。

$array["http://example.com/path/to/site"]["shares"];
于 2013-02-16T17:35:00.133 に答える
1

あなたのプリントアウトによると、にもっと配列があるように見えます$array。これを試して;

echo $array['http://xxxxxxxxx/svce.php']['shares'];
于 2013-02-16T17:37:08.213 に答える