Single byte to width byte

Source: Internet
Author: User
Single byte to width byte
This post was last edited by Sevencolours24 on 2013-02-28 16:05:54

$msg = "China"
Now to send this MSG to another application to receive, how to convert MSG to UTF-16 encoded wide-byte, the application can be displayed correctly
I'm sending it right now, and I found a single byte.


------Solution--------------------
Look at the manual, with the return value of Iconv
$msg = Iconv (' usc-2 ', ' utf-16 ', $msg);
------Solution--------------------
wchar_t is the character data type of C/s + +, an extended character store, the wchar_t type is mainly used in the implementation of internationalized programs, but it is not equivalent to Unicode encoding. Unicode-encoded characters are typically stored in the wchar_t type. Char is a 8-bit character type, can contain up to 256 characters, many foreign language character sets contain more than 256 characters, and a char type cannot be represented.
The wchar_t data type is generally 16-bit or 32-bit, but different C or C + + libraries have different rules, such as the GNU libc wchar_t 32-bit [1], in short, wchar_t can represent more characters than the char type.

So it could just be
Iconv (' Utf-8 ', ' ucs-2 ', $msg)
Iconv (' Utf-8 ', ' ucs-4 ', $msg)
Iconv (' Utf-8 ', ' utf-16 ', $msg)
Iconv (' Utf-8 ', ' utf-32 ', $msg)
One
------Solution--------------------
Header ("Content-type:text/html;charset=utf-8")
This is just the server's response header.
Your file encoding is also utf-8, if not uniform, garbled is normal

  • 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.