Can UTF8 and UTF-8 be mixed in iconv-PHP?

Source: Internet
Author: User
My colleague uses iconv for encoding conversion when UTF8 is used, instead of UTF-8, I tested and found UTF8 and UTF-8 in iconv and mb_str results are the same: iconv (& #039; UTF8 & #039;, & #039; GB2312 & #039;, & #039; Test & #039;); and iconv (& #039; UTF-8 & #039;, & #039; GB2312 & #039;, & #039; Test & #039 ;);. But Google... iconvI tested UTF8 AND THE UTF-8 in iconv and mb_str and the results were the same, as shown in: Iconv ('utf8', 'gb2312', 'test ');And Iconv ('utf-8', 'gb2312', 'test ');. But Google also found that the use of UTF8 rather than UTF-8 problems http://readyfighting.com/archives/156.

So what are the differences between the two?

Reply content:

Use by colleaguesiconvI tested UTF8 AND THE UTF-8 in iconv and mb_str and the results were the same, as shown in:Iconv ('utf8', 'gb2312', 'test ');AndIconv ('utf-8', 'gb2312', 'test ');. But Google also found that the use of UTF8 rather than UTF-8 problems http://readyfighting.com/archives/156.

So what are the differences between the two?

According to the libiconv-1.14/lib/encodings. def, The UTF-8 and UTF8 will be recognized as utf8 encoding, so there is no difference, so all the programs that use libiconv are fine, such as php's iconv library.

/* General multi-byte encodings */DEFENCODING(( "UTF-8",                  /* IANA, RFC 2279 */            /*"UTF8",                      JDK 1.1 */            /*"CP65001",                   Windows */            ),               utf8,            { utf8_mbtowc, NULL },        { utf8_wctomb, NULL })#ifdef USE_HPUX_ALIASESDEFALIAS(     "UTF8",                   /* HP-UX */            utf8)#endif

The UTF-8 (as name/mimename) and UTF8 (as alias) can also be identified based on the mbfilter_utf8.c of ext/mbstring, so the same is true.

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 use 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 windows.

Iconv ('utf8', 'gb2312', 'test ');

Get a warning

Notice: iconv(): Wrong charset, conversion from `UTF8' to `GB2312' is not allowed

This description should be usedUTF-8This form is correct.

Mbstring. supported-encodings only supports the encoding of mbstring.UTF-8This form.

Maybe you can try to modify php. ini

error_reporting = E_ALL | E_STRICTdisplay_errors = On

You can see the warning information.

Test two lines of code as prompted by felix021.

print_r(mb_list_encodings());print_r(mb_encoding_aliases('UTF8'));

We can see that mb is actually processed as an alias.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.