Php string encoding problem 1. PHP encoding conversion function mb_convert_encoding-Convertcharacterencoding (PHP4 & gt; 4.0.6, PHP5) usage: Compile (stringstr, stringto_encoding [, mixedfrom_e php string encoding problem
I. PHP code conversion functions
Mb_convert_encoding-Convert character encoding (PHP 4> = 4.0.6, PHP 5)
Usage:
String mb_convert_encoding (string str, string to_encoding [, mixed from_encoding])
Enable the mbstring extension Library first. in php. ini, remove the extension before php_mbstring.dll.
String iconv (string in_charset, string out_charset, string str)
Note:
The second parameter, in addition to specifying the encoding to be converted, can also add two suffixes: // transcoder and // IGNORE,
Where:
// Transcoder automatically converts a character that cannot be directly converted into one or more similar characters,
// IGNORE ignores the characters that cannot be converted. by default, it is truncated from the first invalid character.
Returns the converted string or FALSE on failure.
II. automatically obtain string encoding functions
When using the mb_detect_encoding function in php for encoding recognition, many people have encountered the problem of incorrect recognition encoding, such, or UTF-8 and GBK (here mainly for the cp936 judgment), said online due to short character is, mb_detect_encoding will be wrong.
For example:
$ Encode = mb_detect_encoding ($ keytitle, array ("ASCII", 'utf-8', "gb2312'," GBK ", 'big5 ′));
If ($ encode = "UTF-8 ″){
$ Keytitle = iconv ("UTF-8", "GBK", $ keytitle );
}
The purpose of this code is to check whether the encoding of the string is UTF-8, if yes, it is converted to GBK.
Here, mb refers to multi-bytes, which is an abbreviation of Qiniu B.