1

I am fetching some string from facebook , but i dont know whitch encoding in string . I need to convert this string into utf8 before inserting into database table . Getting this error message. error screenshot

Here is my php code.

$email = (isset($this->_userinfo['email']) ? $this->_userinfo['email'] : '');
$fname = $this->_userinfo['first_name'];
$lname = $this->_userinfo['last_name'];
$name  = $this->_userinfo['name'];

$sql = 'INSERT INTO users '
     . '(fbid, fbuid, fullname, userlevel, email, name, sirname) '
     . 'VALUES("'
     . $this->_fbid . '","'
     . $fbuid . '","'
     . $name . '","' 
     . $userlevel . '","' 
     . $email . '","' 
     . $fname . '","' 
     . $lname . '")';
Sam
  • 86,580
  • 20
  • 181
  • 179
Taleh Ibrahimli
  • 750
  • 4
  • 13
  • 29
  • The Facebook API should return all data in one standardized encoding. UTF-8 if I'm not completely mistaken. Read http://kunststube.net/frontback. – deceze Sep 21 '12 at 18:06

4 Answers4

4

did you try this code ?

   mysql_query('set names utf8'); 
Afshin
  • 4,197
  • 3
  • 25
  • 34
1

Take a look at utf8_encode to do this for you. Keep in mind this will only work if your data is actually UTF-8 encoded. Unfortunately there is no way to just look at the string and see what encoding it's using.

Oleksi
  • 12,947
  • 4
  • 56
  • 80
1

You might want to take a look at this question:

Detect encoding and make everything UTF-8

especially the second answer by Sebastian Grinoli

He wrote a class (and offers the link to it) which would correctly encode Windows Extended ASCII to UTF8 and also correct UTF8 if necessary.

A really handy tool to have when you are in the UTF8 land :)

Community
  • 1
  • 1
Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
1

enter link description here

For me works following code:

$mysqli = mysqli_connect( ... ); mysqli_query( $mysqli, 'SET NAMES "utf8" COLLATE "utf8_general_ci"' );

or just:

mysqli_set_charset( $mysqli, 'utf8' );

Regards, good luck!

M.Ganji
  • 818
  • 8
  • 13