I tried to use the getid3 class library to extract the song information from mp3 files. most Chinese songs are normal, but a few files are garbled. // & Nbsp; this is the extracted character and its base64 encoded var_dump ($ str, & nbsp; base64_encode ($ str); // & nbsp; how to convert UTF-8 from a GB encoded string
I tried to use the getid3 class library to extract song information from mp3 files. most Chinese songs are normal, but a few files are garbled.
// This is the extracted character and its base64 encoding
Var_dump ($ str, base64_encode ($ str ));
// String (16 )"??????? ±"
// String (24) "w5DDhMOLw4bCv8OxwrPCsQ ="
// Check the character encoding. The result is CP936.
Mb_detect_encoding ($ str, 'gbk, gb2312, GB18030, ISO-8859-1, ASCII, UTF-8 ', true)
// I tried to convert the encoding, but the result is still unsatisfactory.
Mb_convert_encoding ($ str, 'utf-8', 'cp936 ')
// String (24) "Lu halogen"
Because CP936 is compatible with gbk and gb2312, the results are the same. UTF-8 encoding:
------ Solution --------------------
You can also write
Echo iconv ('gbk', 'utf-8', iconv ('utf-8', 'latin1', $ s ));
It is easy to determine whether it is a 2-byte UTF-8 encoding.
Echo (ord ($ s {0}) & 0xf0) = 0xc0? 'Yes': 'not ';
------ Solution --------------------
Reference:
I tried to use the getid3 class library to extract song information from mp3 files. most Chinese songs are normal, but a few files are garbled.
// This is the extracted character and its base64 encoding
Var_dump ($ str, base64_encode ($ str ));
// String (16 )"??????? ±"
// String (24) "w5DDhMOLw4bCv8OxwrPCsQ ="
// Check the character encoding. The result is CP936.
Mb_detect_encoding ($ str, 'gbk, gb2312, GB18030, ISO-8859-1, ASCII, UTF-8 ', true)
// I tried to convert the encoding, but the result is still unsatisfactory.
Mb_convert_encoding ($ str, 'utf-8', 'cp936 ')
// String (24) "Lu halogen"
Because CP936 is compatible with gbk and gb2312, the results are the same.
This should require your server to support some encoding before you can perform conversion. if not, you cannot use program conversion.