Take the 2-minute tour ×

I need to retrieve only first name in facebook app(php sdk).The Below Code Retrieves full name.

$name = $friend['name'];
share|improve this question
list($name,) = explode(" ", $friend['name'], 2); –  Josh Feb 22 '12 at 20:52
i get a error that..imagettftext() expects parameter 8 to be string –  vishnu Feb 22 '12 at 21:08
Provide the relevant code dealing with the error. –  Josh Feb 22 '12 at 21:10

2 Answers 2

You have a look at graph api for that: https://developers.facebook.com/docs/reference/api/

https://graph.facebook.com/4/ gives you:

   "id": "4",
   "name": "Mark Zuckerberg",
   "first_name": "Mark",
   "last_name": "Zuckerberg",
   "link": "https://www.facebook.com/zuck",
   "username": "zuck",
   "gender": "male",
   "locale": "en_US"

For your case try:

$name = $friend['first_name'];
share|improve this answer
Its not working for friends name –  vishnu Feb 22 '12 at 21:25

You can split a string into an array using explode() (http://php.net/manual/en/function.explode.php), then use the first index in that array.


$name = explode(' ', 'Justin Biaber');

which would give

$name[0] = 'Justin', $name[1] = 'Biaber'

share|improve this answer
thanks it worked –  vishnu Feb 23 '12 at 4:53

Your Answer


