Coding in PHP has always been a headache for developers, but if the sweet some useful functions are different, let's introduce a processing function for a Chinese encoding.
Mb_convert_encoding ($str, $encoding 1, $encoding 2)
$str, to convert the encoded string
$encoding 1, the target code, such as UTF-8,GBK, is case-sensitive
$encoding 2, the original code, such as UTF-8,GBK, case can be
Example 1
The code is as follows |
Copy Code |
$str = ' movie 618:http://www.bkjia.c0m '; Echo mb_convert_encoding ($str, "UTF-8"); Convert Encoding to Utf-8 ?> |
Example 2
The code is as follows |
Copy Code |
$str = ' movie 618:http://www.bkjia.c0m '; Echo mb_convert_encoding ($str, "UTF-8", "GBK"); Known original encoded as GBK, converted to Utf-8 ?> |
Example 3
The code is as follows |
Copy Code |
$str = ' movie 618:http://www.bkjia.c0m '; Echo mb_convert_encoding ($str, "UTF-8", "Auto"); Unknown original code, after auto auto-detection, the conversion code is UTF-8 ?> |
Php.net Site Instance
The code is as follows |
Copy Code |
/* Convert internal character encoding to SJIS */ $str = mb_convert_encoding ($str, "SJIS"); /* Convert EUC-JP to UTF-7 */ $str = mb_convert_encoding ($str, "UTF-7", "EUC-JP"); /* Auto detect encoding from JIS, Eucjp-win, Sjis-win, then convert str to Ucs-2le */ $str = mb_convert_encoding ($str, "Ucs-2le", "JIS, Eucjp-win, Sjis-win"); /* "Auto" is expanded to "ascii,jis,utf-8,euc-jp,sjis" */ $str = mb_convert_encoding ($str, "EUC-JP", "Auto"); ?> |
http://www.bkjia.com/PHPjc/632258.html www.bkjia.com true http://www.bkjia.com/PHPjc/632258.html techarticle Coding in PHP has always been a headache for developers, but if the sweet some useful functions are different, let's introduce a processing function for a Chinese encoding. ...