I have variables with chinese words, their charset is GB2312. I want to convert them to UTF-8 because I want to save them to mysql table with utf-8 encoding. How to do that is PHP? I'm using PHP 7.
Here are what I have tried:
- I have tried using
$myvar = iconv('gb2312', 'utf-8', $myvar);
However some of my variables get empty if it contains some characters (invalid UTF-8 chars maybe?) - I have tried using
$myvar = mb_convert_encoding($myvar, 'UTF-8', 'GB2312');
It works better thaniconv
but when$myvar
contain some characters as I mentioned above, they turned into question mark (?
)
Please help me, thanks
Update Here is an example of my chinese string:
- GB2312 (Expected result): 第3章︰林鴻
- Using
mb_convert_encoding
become: 第3章?林? - Using
iconv
become empty