- Print_r (iconv_get_encoding ("all "));
2. encode and convert the specified string:
- Echo iconv ('utf-8', 'gb2312', 'Ours '); // Convert 'Ours from utf8 to gb2312 encoding.
- ** Iconv (in_charset, outcharset // Transcoder // IGNORE, $ string); // 'transtransencoding': If the output encoding format does not contain any character, you can search for replacement in the similar encoding; 'ignore': If the output format encoding does not contain a character in the string, you can skip the subsequent encoding. Otherwise, output will be interrupted when transcoding fails and an error will be generated.
3. encode and convert strings (the encoding type can be determined automatically, but I heard the efficiency is not as good as iconv .)
- Mb_convert_encoding ('Ours ', 'utf-8', 'gb2312'); // Convert 'Ours from gb2312 to utf8
- Mb_convert_encoding ('Ours ', 'utf-8'); // Convert 'Ours' to utf8 encoding format
- $ Str = mb_convert_encoding ($ str, "EUC-JP", "auto ");
- $ Str = mb_convert_encoding ($ str, "UCS-2LE", "JIS, eucjp-win, sjis-win ");
- ** The third parameter can also be in the array () format.
When talking about the usage of the mb_convert_encoding encoding conversion function, you can read the following:
- Php code conversion functions mb_convert_encoding and iconv
- Php code conversion functions: mb_convert_encoding and iconv
4. set the encoding format:
- Iconv_set_encoding ("internal_encoding", "UTF-8"); // set the internal encoding to utf8
- Iconv_set_encoding ("output_encoding", "ISO-8859-1"); // sets the output encoding to a ISO-8859-1
- Setting options: 1. input_encoding 2. output_encoding 3. internal_encoding
- ** ISO-8859-1 encoding is single-byte encoding, downward compatible with ASCII, Latin1 is an alias for the ISO-8859-1
5. view the string encoding method: format: string mb_detect_encoding (string $ str [, mixed $ encoding_list = mb_detect_order () [, bool $ strict = false])
- $ Str = 'Encoding method ';
- Echo mb_detect_encoding ($ str); // UTF-8
- Echo mb_detect_encoding ($ str, "auto ");
- Echo mb_detect_encoding ($ str, "JIS, eucjp-win, sjis-win ");
- $ Ary [] = "ASCII ";
- $ Ary [] = "JIS ";
- $ Ary [] = "EUC-JP ";
- Echo mb_detect_encoding ($ str, $ ary );
6. view the file encoding method:
- $ File = 'text3.txt ';
- Echo getFileEncoding (file_get_contents ($ file); // output UTF-16LE
7. check whether the string complies with the specified format encoding: format: bool mb_check_encoding ([string $ var = NULL [, string $ encoding = mb_internal_encoding ()])
- $ String = "\ x00 \ x81 ";
- $ Encoding = "Shift_JIS ";
- Mb_check_encoding ($ string, $ encoding) //: true
8. character encoding conversion of one or more variables: format: stringmb_convert_variables (string $ to_encoding, mixed $ from_encoding, mixed & $ vars [, mixed & $...]) ** $ from_encoding: it can be a number, separated by commas.
- $ Str1 = 'Test code'; $ str21 = 'Test code2 ';
- $ Inputenc = mb_convert_variables ("UTF-8", "UTF-8, GBK, GB2312", $ str1, $ str2 );
- Var_dump ($ inputenc); //: string (5) "UTF-8"
- Var_dump ($ str1); //: string (12) "test code"
- ** CP936 is GBK
|