tags:

views:

113

answers:

1

I am currently getting data from a users profile when they login through facebook, I want to store this data for signup process on my site. When accessing "hometown" it lists it as one such as:

London, Westminster, United Kingdom

The hometown is in an array as follows:

>  [hometown] => Array
>         (
>             [id] => 000000000
>             [name] => London, Westminster, United Kingdom
>         )

I access the town name by using the code

<?php echo $me['hometown']['name']; ?>

Would it be possible to have each part single? So that I could have, town, country etc

I am using Facebook php SDK Thanks :)

+1  A: 

You can use:

$hometown=explode(",",$me['hometown']['name']);

echo $hometown[0]; //London
echo $hometown[1]; //Westminster
echo $hometown[2]; //United Kingdom

edited: changed to explode as "split()" is deprecated as of php 5.3

Josh Stuart
Perfect, just what I wanted :) Thanks!
Elliott
Might need to use trim($hometown[0]); so that you remove the whitespace from the parts. otherwise it could be " United Kingdom" instead of "United Kingdom". Just a little tweak :D
Josh Stuart