Copy codeThe Code is as follows:
Iconv ('gbk', 'utf-8 // IGNORE ', 'feet home'); // converts a string from GBK encoding to UTF-8 Encoding
However, iconv can only solve the problem of pre-known encoding. If the string encoding is unknown, you need to first detect its encoding. In this case, the mb_string extension library may be used:
Copy codeThe Code is as follows:
Mb_detect_encoding ('foot home ');
However, mb_detect_encoding has a hard injury, which often results in inaccurate judgment. This may solve the problem:
Copy codeThe Code is as follows:
// Use iconv to convert and determine whether the value is equal. The efficiency is not high.
Function is_utf8 ($ str ){
If ($ str = iconv ('utf-8', 'utf-8 // IGNORE ', $ str )){
Return 'utf-8 ';
}
}
// Multiple encoding conditions
Function detect_encoding ($ str ){
Foreach (array ('gbk', 'utf-8') as $ v ){
If ($ str = iconv ($ v, $ v. '// IGNORE', $ str )){
Return $ v;
}
}
}
After obtaining the string encoding information, you can use iconv or mb_convert_encoding to convert the encoding information.