Number prototype: String Iconv (String $in _charset, String $out _charset, String $str)
In particular, the second parameter description:
The output charset.
When using Iconv () to convert an output character encoding an unsupported character, such as Iconv (' Utf-8 ', ' gb2312 ', ' www.bKjia.c0m '), you will encounter such an error message:
Notice:iconv () [Function.iconv]: detected an illegal character in input string ...
Because gb2312 represents simplified Chinese and does not support more complex Chinese characters such as "www.bKjia.c0m" and some special characters, this is of course an error, and there are two ways to solve them:
1. Expand the range of output character encodings, such as Iconv (' Utf-8 ', ' gbk ', ' www.bKjia.c0m '), and you can output them correctly, because GBK supports a wider range of characters;
2. After the output of the character encoding string with "//ignore", such as Iconv (' Utf-8 ', ' gb2312//ignore ', ' www.bKjia.c0m '), this is actually ignoring the characters that cannot be converted, avoiding errors but not being able to output correctly ( That is, the blank is not, output).
Here's a look at PHP tutorial Iconv (): detected an illegal character in input string processing method
$str = Iconv (' utf-8 ', ' Gbk//ignore ', unescape (isset ($_get[' str '))? $_get[' str ']: ");
Local test//ignore can ignore the words it does not know and then go down, and do not error, and//translit is to cut off the words it does not know and the contents behind, and error. Ignore is what I need.
Now wait for the line to see the results (this is not a good practice, continue to ponder the manual, search the Internet), hehe ...
Find the following article on the Internet, found that mb_convert_encoding can also, but efficiency than iconv poor.
The difference between the conversion string encoding Iconv and mb_convert_encoding
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:
String mb_convert_encoding (String str, string to_encoding [, mixed from_encoding])
Need to enable mbstring extension library, in php.ini; Extension=php_mbstring.dll in front of; Remove
String Iconv (String in_charset, String out_charset, String str)
Attention:
The second parameter, in addition to specifying the encoding to be converted to, can also add two suffixes://translit and//ignore,
which
Translit automatically converts characters that cannot be converted directly into one or more approximate characters,
Ignore ignores characters that cannot be converted, and the default effect is to truncate from the first illegal character.
Returns the converted string or false on failure.
Use:
1. Iconv is found to have an error converting the character "-" to gb2312, and if there is no ignore parameter, all strings after that character cannot be saved. In any case, this "-" can not be converted successfully, unable to output. Another mb_convert_encoding does not have this bug.
2. Mb_convert_encoding can specify a number of input encodings, which will be automatically recognized based on content, but the execution efficiency is much worse than iconv, such as: $str = mb_convert_encoding ($str, "EUC-JP", "Ascii,jis , Euc-jp,sjis,utf-8 "); Ascii,jis,euc-jp,sjis,utf-8 "The order of the different effects also have differences
3. In general, with Iconv, only when encountering the inability to determine the encoding of the original encoding, or iconv conversion can not be normal display when the mb_convert_encoding function
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 would be used.
$str = mb_convert_encoding ($str, "Ucs-2le", "JIS, Eucjp-win, Sjis-win");
$str = mb_convert_encoding ($str, "EUC-JP", "Auto");
http://www.bkjia.com/PHPjc/632348.html www.bkjia.com true http://www.bkjia.com/PHPjc/632348.html techarticle number prototype: String Iconv (String $in _charset, String $out _charset, string $str) in particular the second parameter description: The output charset. Using Iconv () conversion An output character encoding is not ...