- Print_r (iconv_get_encoding ("All"));
Copy Code2, encode the string to convert:
- echo iconv (' Utf-8 ', ' gb2312 ', ' we '); Convert ' us ' from UTF8 encoding to gb2312 encoding
- **iconv (In_charset,outcharset//translit//ignore, $string);//' translit ': if there are no characters in the encoded format of the output, you can find the substitution in similar encodings; ' IGNORE ': If the output format encoding does not contain a character in a string, the encoding of subsequent characters can be skipped. Otherwise, the output is interrupted at transcoding failure, resulting in an error.
Copy Code3, the string encoding conversion (can automatically determine the encoding type, but heard that efficiency is not iconv good. )
- Mb_convert_encoding (' we ', ' utf-8 ', ' gb2312 '); Convert ' us ' from gb2312 to UTF8
- Mb_convert_encoding (' we ', ' utf-8 '); Convert ' us ' to UTF8 encoded 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 an array () Form
Copy CodeWhen it comes to the use of mb_convert_encoding encoding conversion functions, you can read:
- PHP Code conversion function mb_convert_encoding and Iconv
- PHP Code conversion function mb_convert_encoding and iconv usage instructions
4. Set the encoding format:
- Iconv_set_encoding ("internal_encoding", "UTF-8"); Set internal encoding to UTF8
- Iconv_set_encoding ("output_encoding", "iso-8859-1"); Set output encoding to Iso-8859-1
- Setting options: 1.input_encoding 2.output_encoding 3.internal_encoding
- **ISO-8859-1 encoding is single byte encoded, backwards compatible with ASCII, Latin1 is iso-8859-1 alias
Copy Code5. View string Encoding: Format: String mb_detect_encoding (string$str[,mixed$encoding_list= mb_detect_order () [, bool$strict= false]] )
- $STR = ' encoding ';
- 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);
Copy Code6. View the file encoding method:
- $file = ' text3.txt ';
- Echo getfileencoding (file_get_contents ($file)); Output Utf-16le
Copy Code7, determines whether the string conforms to 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
Copy Code8, character encoding conversion for single or multiple variables: format: stringmb_convert_variables (string$to_encoding,mixed$from_encoding,mixed& $vars [, Mixed &$ ...] * * * $from _encoding: Can be in the form of numbers, separated by commas in string or struct form.
- $str 1 = ' test code '; $str 21 = ' Test Code 2 ';
- $inputenc = Mb_convert_variables ("UTF-8", "utf-8,gbk,gb2312", $str 1, $str 2);
- Var_dump ($INPUTENC); : String (5) "UTF-8"
- Var_dump ($str 1); : String (12) "Test Code"
- **cp936 is GBK.
Copy Code |