php - Counting results displayed -


i know how count how many people follows in instagram , place number in var, instagram gives link:

https://api.instagram.com/v1/users/3/followed-by?access_token=xxxxxxxxx.xxxxxxxxxxxxxxxxxxxx 

and displays result so

{     "data": [{         "username": "meeker",         "first_name": "tom",         "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_6623_75sq.jpg",         "id": "6623",         "last_name": "meeker"     },     {         "username": "mark",         "first_name": "mark",         "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg",         "id": "29648",         "last_name": "shin"     },     {         "username": "nancy",         "first_name": "nancy",         "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg",         "id": "13096",         "last_name": "smith"     }] } 

how can count how many there , place in var, lets say:

<? echo "you been follow ".$followers." users!"; ?> 

to display: been follow 3 users!

you need use json_decode to decode json response, access resulting object's data attribute (an array of 'follower' objects), , count that:

$json = '{     "data": [{         "username": "meeker",         "first_name": "tom",         "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_6623_75sq.jpg",         "id": "6623",         "last_name": "meeker"     },     {         "username": "mark",         "first_name": "mark",         "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg",         "id": "29648",         "last_name": "shin"     },     {         "username": "nancy",         "first_name": "nancy",         "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg",         "id": "13096",         "last_name": "smith"     }] }'; $json = json_decode($json); echo "you have " .count($json->data) ." followers" 

or

$json = json_decode($json,true); echo "you have " .count($json['data']) ." followers" 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -