Copy CodeThe code is as follows:
Iconv (' GBK ', ' utf-8//ignore ', ' home of the script '); Converts a string from GBK encoding to UTF-8 encoding
However, Iconv can only solve the pre-known encoding situation, if the string encoding is unknown, you need to first probe its encoding, you may use the Mb_string extension library:
Copy the Code code as follows:
Mb_detect_encoding (' Home of the script ');
But mb_detect_encoding there is a mishap, often appear to judge inaccurate situation. Perhaps this will solve:
Copy the Code code as follows:
Use Iconv to convert and determine whether the equivalence is not high efficiency
function Is_utf8 ($STR) {
if ($str = = = Iconv (' UTF-8 ', ' Utf-8//ignore ', $str)) {
Return ' UTF-8 ';
}
}
Multiple coding scenarios
function detect_encoding ($STR) {
foreach (Array (' GBK ', ' UTF-8 ') as $v) {
if ($str = = = Iconv ($v, $v. '//ignore ', $str)) {
return $v;
}
}
}
After getting the string encoding information in the above way, you can use Iconv or mb_convert_encoding to convert the encoding.
http://www.bkjia.com/PHPjc/774997.html www.bkjia.com true http://www.bkjia.com/PHPjc/774997.html techarticle Copy the code as follows: Iconv (' GBK ', ' utf-8//ignore ', ' home of the script ');//Convert the string from GBK encoding to UTF-8 encoding, but Iconv can only resolve the case where the encoding is known beforehand, if ...