Reputation: 1478
I've just started learning facebook application development where i need to get facebook group id by name if its a string and as it is(integer) if its number. Now, what i've done till now is:
if(isset($_POST['scrape'])):
$group_id = $_POST['gid'];
if(!(int)$group_id)
{
$fb_group_array = file_get_contents("http://graph.facebook.com/".$group_id);
}
endif;
where $fb_group_array outputs something like this:
{
"is_published": true,
"personal_info": "This group is where u Share Adult Jokes and Funny pictures.\nOnly \" BOYS \" with real identity are welcome to the group.\n( RULE: NO FIGHTS BETWEEN OUR BROTHERS, RESPECT; BEHAVE AND SALUTE to our BROTHERHOOD )\n(NOTE: ADULT CONTENTS, 18+ ONLY, GIRLS AND GAYS PROHIBITED)\nThank you. :)",
"talking_about_count": 0,
"username": "MENSROOMrELOADED",
"were_here_count": 0,
"category": "Public figure",
"id": "429748430401621",
"name": "M E N S R O O M (r E L O a D E D )",
"link": "https://www.facebook.com/MENSROOMrELOADED",
"likes": 137
}
Now i want extract data from this output as id, username etc. I tried exploding them and its works well however im sure there is better way to do it, like converting to PHP array or JSON. Please lead me to the right direction. Thank you.
Upvotes: 0
Views: 185
Reputation: 75981
Use json_decode
, like this:
$fb_group_obj = json_decode($fb_group_array, true);
$group_fbid = $fb_group_obj['id'];
Upvotes: 3