Take the 2-minute tour ×

I am trying to get the number of likes of a particular page on my website and store it in an array. Stuck in middle, i figured out that i can get the number of likes along with other data by the following code:

$graph= file_get_contents($site);

the output is as follows:


is there a way i can just store the number of likes i.e. in this case 75 in a php array?

I tried explode(); but the problem is that the url that i would be using wont be of a constant length.

share|improve this question
That data format is called JSON, so look up json_decode in the manual. Btw., if you would use the PHP SDK, it would do the necessary stuff for you automatically. –  CBroe Feb 15 '13 at 12:15
@CBroe yea i guessed it was JSON but was just curious if this can be done using PHP by the same output results. Thanks anyways –  Arihant Feb 15 '13 at 12:21
Why don't you use the PHP SDK? Its a lot easier and its more future-proof. –  Facebook Answers Feb 15 '13 at 13:14
@FacebookAnswers, what if i have multiple like buttons on the same page and if they arent the like buttons for facebook pages but my website's particular pages –  Arihant Feb 15 '13 at 19:05

1 Answer 1

up vote 1 down vote accepted

This is a json string decode it, use json_decode you will get the output as array. ref : http://php.net/manual/en/function.json-decode.php

$array  = json_deocde($json_string, true);

echo "<pre>";
share|improve this answer
Did get the values in array but a stupid question, it says 'Array (....[shares]=>75.....)' How do i get this to a variable? What index should i give to the array? –  Arihant Feb 15 '13 at 12:30
$var = $array['shares']; –  Prasanth Bendra Feb 15 '13 at 12:49
I tried that , it didn't work. It gave a following Notice: Undefined index: shares in C:\xampp\htdocs\graphapi.php on line 19 –  Arihant Feb 15 '13 at 15:49

Your Answer


