tags:

views:

346

answers:

3

Currently I have something like this \u4eac\u90fd and I want to convert it to UTF-8 so I can insert it into a database.

+1  A: 

Most likely, the \u escape sequence was already sent by the web browser. This would be the original source of your problem - you need to make the web browser stop doing that.

For that, you need to make sure that the browser knows what encoding to use when submitting the form. The browser will, by default, always use the encoding of the HTML page that contains the form. Make sure that this web page is encoded in UTF-8, and has an UTF-8 charset declaration in a meta header. With that done, the browser should submit UTF-8 data correctly, and you shouldn't need to convert anything at all.

Martin v. Löwis
A: 

i tried it this way

    $chinaarray = explode("\\",$value);
for($i=0;$i<=sizeOf($chinaarray);$i++){
 $unicodething .= "&#".hexdec(trim($chinaarray[$i])).";";
}

$value = html_entity_decode(trim($unicodething), ENT_QUOTES, 'UTF-8');

but the problem is that i get that weird ? question mark in a black square at the end

+2  A: 

http://hsivonen.iki.fi/php-utf8/

troelskn