First, detect the current string encoding and change the encoding to Utf-8
1 Gets the encoding of the current string
$encode = mb_detect_encoding ($str, Array ("ASCII", ' UTF-8 ', "GB2312", "GBK", ' BIG5 '));
2 change character encoding to Utf-8
$str _encode = mb_convert_encoding ($str, ' UTF-8 ', $encode);
Second, the function of the detailed
1 mb_detect_encoding - encoding of the detection character
Descriptionstringmb_detect_encoding( string $str[, mixed $encoding _list = Mb_detect_order () [, bool $strict = False ]] )
Detects the encoding of the string str.
Parameter str
The string to be checked.
Encoding_list
Encoding_list is a list of character encodings. The encoding order can be specified by an array or comma-delimited list string.
If Encoding_list is omitted, the Detect_order will be used.
Strict
Strict specifies whether to strictly detect the encoding. The default is FALSE.
return value
The character encoding is detected, or FALSEis returned if the encoding of the specified string cannot be detected.
2 mb_convert_encoding - encoding of converted characters
Descriptionstringmb_convert_encoding( string $str, string $to _encoding[, mixed $from _encoding = mb_internal_encoding () ] )
Converts the character encoding of the string type str from an optional from_encoding to a to_encoding.
Parameter str
The stringto encode.
To_encoding
The type of encoding to which STR is to be converted.
From_encoding
specified by the character code name before conversion. It can be an array or a comma-delimited list of enumerations. If from_encoding is not provided, the internal (internal) encoding is used.
See supported encodings.
return value
The encoded string.
PHP detects current character encoding and transcoding