PHP detects the current character encoding and transcode 1. detects the current string encoding and changes the encoding to UTF-8
1. obtain the encoding of the current string.
$ Encode = mb_detect_encoding ($ str, array ("ASCII", 'utf-8', "GB2312", "GBK", 'big5 '));
2. change the character encoding to UTF-8.
$ Str_encode = mb_convert_encoding ($ str, 'utf-8', $ encode );
II. Function Details
1Mb_detect_encoding?Encoding of detected characters
Description
String mb_detect_encoding (string $ str [, mixed $ encoding_list = mb_detect_order () [, bool $ strict = false])
Checks the str encoding of a string.
Parameter str
The string to be checked.
Encoding_list
Encoding_list is a character encoding list. The encoding sequence can be specified by list strings separated by arrays or commas.
If encoding_list is omitted, detect_order is used.
Strict
Strict specifies whether the encoding is strictly checked. The default value is FALSE.
Return value
The detected character encoding, or FALSE is returned if the encoding of the specified string cannot be detected.
2Mb_convert_encoding?Conversion character encoding
Description
String mb_convert_encoding (string $ str, string $ to_encoding [, mixed $ from_encoding = mb_internal_encoding ()])
Convert the string-type str character encoding from the optional from_encoding to to_encoding.
Parameter str
The string to be encoded.
To_encoding
The encoding type to convert str.
From_encoding
Before conversion, use the character code name. It can be an array or a comma-separated enumerated list. If from_encoding is not provided, internal (internal) encoding is used.
See supported encoding.
Return value
The encoded string.