Iconv & mdash; Convertstringtorequestedcharacterencoding (PHP4 & gt; 4.0.5, PHP5) mb_convert_encoding & mdash; Convertcharacterencoding (PHP4 & gt; 4.0.6, PHP5) usage: iconv-Convert string to requested character encoding (PHP 4> = 4.0.5, PHP 5)
Mb_convert_encoding-Convert character encoding (PHP 4> = 4.0.6, PHP 5)
Usage:
Iconv
String iconv (string $ in_charset, string $ out_charset, string $ str)
Converts a string from one specified encoding to another. note that the second parameter can contain two suffixes in addition to specifying the encoding to be converted. // 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, the result is truncated from the first illegal character. for example:
// Convert "Welcome to WEB Development Network" from gb2312 encoding to UTF-8 encoding echo iconv ('gb2312', 'utf-8, "Welcome to WEB Development Network ");
Small traps for iconv transcoding in PHP
It is found that iconv will encounter an error when converting the character "-" (character after ascii code 150) to gb2312. without the ignore parameter, all strings after this character cannot be saved. In any case, the "-" cannot be converted successfully or output. In addition, mb_convert_encoding does not have this bug.
Generally, iconv is used. the mb_convert_encoding function is used only when the encoding of the original encoding cannot be determined or The iconv cannot be normally displayed after conversion.
From_encoding is specified by character code name before conversion. it can be array or string-comma separated enumerated list. If it is not specified, the internal encoding will be used.
/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */
$ Str = mb_convert_encoding ($ str, "UCS-2LE", "JIS, eucjp-win, sjis-win ");
/* "Auto" is expanded to "ASCII, JIS, UTF-8, EUC-JP, SJIS "*/
$ Str = mb_convert_encoding ($ str, "EUC-JP", "auto ");
12 Next page