GB system encoding how to convert Utf-8

Source: Internet
Author: User
Code Utf-8

I try to use the Getid3 class Library from the MP3 file to extract the song information, most Chinese songs are normal, but a small number of files have garbled situation.

This is the extracted character, and it's Base64 encoded
Var_dump ($str, Base64_encode ($STR));
String (16) "Ðäëæ¿ñ³±"
String ("w5ddhmolw4bcv8oxwrpcsq==")

Detect character encoding, the result is CP936
Mb_detect_encoding ($str, ' GBK, gb2312, GB18030, Iso-8859-1, ASCII, UTF-8 ', true)

I try to convert this than coding, but the results are still not ideal
Mb_convert_encoding ($str, ' UTF-8 ', ' CP936 ')
String ("????") Donkey Hat lu Halogen "

Because CP936 and GBK are compatible with gb2312, the results are the same.


Reply to discussion (solution)

$s = "w5ddhmolw4bcv8oxwrpcsq==";
$s = base64_decode ($s);//ðäëæ¿ñ³± (this is UTF-8 encoded)
echo Utf8_decode ($s);//Heart like frenzy (note that this is GBK encoded)

Since your system does not recognize the GBK encoding, each extended ASCII character that makes up the GBK string is iso-8859-1 to utf-8 encoding conversion

You can write, too.
echo iconv (' GBK ', ' Utf-8 ', iconv (' Utf-8 ', ' latin1 ', $s));

It is also easy to determine if the Utf-8 encoding is 2 bytes
Echo (Ord ($s {0}) & 0xf0) = = 0xc0? ' Yes ': ' No ';

I try to use the Getid3 class Library from the MP3 file to extract the song information, most Chinese songs are normal, but a small number of files have garbled situation.

This is the extracted character, and it's Base64 encoded
Var_dump ($str, Base64_encode ($STR));
String (16) "Ðäëæ¿ñ³±"
String ("w5ddhmolw4bcv8oxwrpcsq==")

Detect character encoding, the result is CP936
Mb_detect_encoding ($str, ' GBK, gb2312, GB18030, Iso-8859-1, ASCII, UTF-8 ', true)

I try to convert this than coding, but the results are still not ideal
Mb_convert_encoding ($str, ' UTF-8 ', ' CP936 ')
String ("????") Donkey Hat lu Halogen "

Because CP936 and GBK are compatible with gb2312, the results are the same.
This should still have to be your server support some kind of code, you can do the conversion, if not supported, you cannot use the program to convert the

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.