php import utf-8 txt file to latin1 database
I have an UTF-8 encoded txt file and I want to import it to latin1_general_ci table. Problem is that some characters display as ? in database and not 开发者_运维百科as they supposed to.
I tried mb_convert_encoding($str, "ISO-8859-1", "UTF-8"); but that didn't do anything.
What am I doing wrong?
Latin1 doesn't include all Unicode characters. You can use iconv() with //TRANSLIT option to transliterate unknown characters to their closest latin1 equivalents:
iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text)
I use utf8_decode, it works for me.
You can convert them to binary and then convert it back to latin
insert into table values
(convert(binary convert(data using utf8) using latin1))
精彩评论