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