PHP GBK conversion UTF8 missing characters and garbled solution _php Tutorial

Source: Internet
Author: User
In PHP if we convert the UFT8 string to GBK or gb2312 will appear garbled or missing problem, because GBK encoding range and UFT8 encoding range of problems, below we simply listed a GBK and UTF8 coding range table, see To know why.

One, the coding range
1. GBK (gb2312/gb18030)
X00-xff GBK Double byte encoding range
x20-x7f ASCII
Xa1-xff Chinese
X80-xff Chinese


2. UTF-8 (Unicode)
U4E00-U9FA5 (English)
x3130-x318f (Korean
XAC00-XD7A3 (Korean)
u0800-u4e00 (Japanese)

PS: Korean is more than [U9FA5] characters

Cases

The code is as follows Copy Code

$c = ' Test • Word nginx • 51 Happy! ';

echo iconv (' Utf-8 ', ' GBK ', $c);

Output only: After the test, the plenary is lost.

Workaround:

Add//ignore

The code is as follows Copy Code

$c = ' Test • Word nginx • 51 Happy! ';

echo iconv (' Utf-8 ', ' Gbk//ignore ', $c);

Input: Test word nginx 51 happy!

Example 2

The code is as follows Copy Code
echo $str = ' Hello, here is coffee! ';
Echo '
';
echo iconv (' GB2312 ', ' UTF-8 ', $str); To transfer the encoding of a string from GB2312 to UTF-8
Echo '
';
Echo Iconv_substr ($STR, 1, 1, ' UTF-8 '); Intercept by number of characters rather than bytes
Print_r (Iconv_get_encoding ()); Get the current page encoding information
Echo Iconv_strlen ($str, ' UTF-8 '); Gets the string length of the set encoding
?>

http://www.bkjia.com/PHPjc/632129.html www.bkjia.com true http://www.bkjia.com/PHPjc/632129.html techarticle in PHP If we convert the UFT8 string to GBK or gb2312 will appear garbled or missing problem, because GBK encoding range and UFT8 encoding range of problems, below we simply listed a ...

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