Colleagues use
iconv
When encoding conversion is used when UTF8, instead of UTF-8, I tested the next found UTF8 and UTF-8 in Iconv and MB_STR results are the same, such as:
iconv('UTF8', 'GB2312', '测试');
And
iconv('UTF-8', 'GB2312', '测试');
。 But Google also found that some people because of the use of UTF8 rather than UTF-8 encounter problems http://readyfighting.com/archives/156.
So what's the difference between using them?
Reply content:
When a colleague uses iconv
the encoding conversion when using the UTF8 instead of the UTF-8, I tested the next found UTF8 and UTF-8 in Iconv and MB_STR results are the same, such as: iconv('UTF8', 'GB2312', '测试');
and iconv('UTF-8', 'GB2312', '测试');
. But Google also found that some people because of the use of UTF8 rather than UTF-8 encounter problems http://readyfighting.com/archives/156.
So what's the difference between using them?
According to Libiconv-1.14/lib/encodings.def, UTF-8 and UTF8 will be identified as UTF8 encoding, so there is no difference, so all programs that use Libiconv are fine, such as the PHP iconv library.
/* General Multi-Byte Encodings */defencoding (("UTF-8",/ * IANA, RFC 2279 */ * "UTF8", JDK 1.1 */ * "CP6 5001 ", Windows */ ), utf8, {UTF8_MBTOWC, null}, {utf8_wctomb, null}) #ifdef USE_HPUX_ Aliasesdefalias ( "UTF8",/ * HP-UX */ UTF8) #endif
According to Ext/mbstring's mbfilter_utf8.c, UTF-8 (as Name/mimename) and UTF8 (as Alias) can also be identified, so is the same.
static const char *mbfl_encoding_utf8_aliases[] = {"UTF8", null};const mbfl_encoding Mbfl_encoding_utf8 = { Mbfl_no _encoding_utf8, "UTF-8", "UTF-8", (const char * (*) []) &mbfl_encoding_utf8_aliases, Mblen_ Table_utf8, Mbfl_enctype_mbcs};
By the way, MySQL does not recognize utf-8 and must be UTF8.
mysql> CREATE TABLE t1 (ID int primary key, name int) character Set utf-8;
ERROR 1115 (42000): Unknown character set: ' UTF '
Hello, I tested a line of code in the Windows environment
Iconv (' UTF8 ', ' GB2312 ', ' test ');
Get a warning
Notice:iconv (): Wrong charset, conversion from ' UTF8 ' to ' GB2312 ' are not allowed
This means that the form of UTF-8 should be used correctly.
Mbstring.supported-encodings mentioned in the mbstring supported encoding is also only UTF-8 this form.
Maybe you can try to modify the php.ini.
error_reporting = E_all | E_strictdisplay_errors = On
Maybe you can see the warning message.
Test two lines of code according to FELIX021 's tips
Print_r (Mb_list_encodings ());p Rint_r (mb_encoding_aliases (' UTF8 '));
It is true that MB is treated as an alias.