汉字编码问题_PHP
一、GB2312-80介绍
GB2312码是中华人民共和国国家汉字信息交换用编码,全称《信息交换用汉字编码字符集--基本集》,由国家标准总局发布,1981年5月1日实施,通行于大陆。新加坡等地也使用此编码。
GB2312收录简化汉字及符号、字母、日文假名等共7445个图形字符,其中汉字占6763个。GB2312规定“对任意一个图形字符都采用两个字节表示,每个字节均采用七位编码表示”,习惯上称第一个字节为“高字节”,第二个字节为“低字节”。GB2312-80包含了大部分常用的一、二级汉字,和9区的符号。该字符集是几乎所有的中文系统和国际化的软件都支持的中文字符集,这也是最基本的中文字符集。其编码范围是高位0xa1-0xfe,低位也是0xa1-0xfe;汉字从0xb0a1开始,结束于0xf7fe。
GB2312将代码表分为94个区,对应第一字节(0xa1-0xfe);每个区94个位(0xa1-0xfe),对应第二字节,两个字节的值分别为区号值和位号值加32(2OH),因此也称为区位码。01-09区为符号、数字区,16-87区为汉字区(0xb0-0xf7),10-15区、88-94区是有待进一步标准化的空白区。GB2312将收录的汉字分成两级:第一级是常用汉字计3755个,置于16-55区,按汉语拼音字母/笔形顺序排列;第二级汉字是次常用汉字计3008个,置于56-87区,按部首/笔画顺序排列。故而GB2312最多能表示6763个汉字。
GB2312的编码范围为2121H-777EH,与ASCII有重叠,通行方法是将GB码两个字节的最高位置1以示区别。
图1:GB2312编码图
图中位于ASCII区中的虚线区域即为原GB2312编码区域,右下角实线区域为平移后的GB2312编码区域。
二、GB2312-80的扩展
GBK是GB2312-80的扩展,是向上兼容的。它包含了20902个汉字,其编码范围是0x8140-0xfefe,剔除高位0x80的字位。其所有字符都可以一对一映射到Unicode2.0。
GB18030-2000(GBK2K)在GBK的基础上进一步扩展了汉字,增加了藏、蒙等少数民族的字形。GBK2K从根本上解决了字位不够,字形不足的问题。它有几个特点:
l 它并没有确定所有的字形,只是规定了编码范围,留待以后扩充。
l 编码是变长的,其二字节部分与GBK兼容;四字节部分是扩充的字形、字位,其编码范围是首字节0x81-0xfe、二字节0x30-0x39、三字节0x81-0xfe、四字节0x30-0x39。
l 它的推广是分阶段的,首先要求实现的是能够完全映射到Unicode3.0标准的所有字形。
l 它是国家标准,是强制性的。
l 现在还没有任何一个操作系统或软件实现了GBK2K的支持,这是现阶段和将来汉化的工作内容。
三、Unicode编码
国际标准组织于1984年4月成立ISO/IECJTC1/SC2/WG2工作组,针对各国文字、符号进行统一性编码。1991年美国跨国公司成立UnicodeConsortium,并于1991年10月与WG2达成协议,采用同一编码字集。目前Unicode是采用16位编码体系,其字符集内容与ISO10646的BMP(BasicMultilingualPlane)相同。Unicode于1992年6月通过DIS(DrafInternationalStandard),目前版本V2.0于1996公布,内容包含符号6811个,汉字20902个,韩文拼音11172个,造字区6400个,保留20249个,共计65534个。
随着国际互联网的迅速发展,要求进行数据交换的需求越来越大,不同的编码体系越来越成为信息交换的障碍,而且多种语言共存的文档不断增多,单靠代码页已很难解决这些问题,于是UNICODE应运而生。
UNICODE有双重含义,首先UNICODE是对国际标准ISO/IEC10646编码的一种称谓(ISO/IEC10646是一个国际标准,亦称大字符集,它是ISO于1993年颁布的一项重要国际标准,其宗旨是全球所有文种统一编码),另外它又是由美国的HP、Microsoft、IBM、Apple等大企业组成的联盟集团的名称,成立该集团的宗旨就是要推进多文种的统一编码。
UNICODE同现在流行的代码页最显著不同点在于:UNICODE是两字节的全编码,对于ASCII字符它也使用两字节表示。代码页是通过高字节的取值范围来确定是ASCII字符,还是汉字的高字节。如果发生数据损坏,某处内容破坏,则会引起其后汉字的混乱。UNICODE则一律使用两个字节表示一个字符,最明显的好处是它简化了汉字的处理过程。
UNICODE使用平面来描述编码空间,每个平面分为256行,256列,相对于两字节编码的高低两个字节。
UNICODE的第一个平面,称为BasicMultilingualPlane(基本多文种平面),简称BMP,由于BMP仅用两个字节表示,所以倍受青睐。
图2:BMP的最新概貌图
其中A_ZONE为拼音文字编码区,拉丁文、阿拉伯文、日文的平假名及片假名等都在此区编码。CJKExtensionA和CJK为汉字区域共计27487个汉字。Y1即彝文,位于O-ZONE保留待将来使用。Hangul即韩文。EUDC为用户私有区,用户可以根据需要自己定义此区的编码。R-ZONE为限制使用区,一些兼容字符、特殊字符均放在此区。
UNICODE定义BMP中的D800-DFFF为代理区(SurrogateZone),其中D800-D8FF为高半代理(highsurrogate),DC00-DFFF为低半代理(lowsurrogate)。从两个区域分别取一个编码,组成一个4字节的代理对来表示一个编码字符,此即为UTF-16。利用UTF-16机制,UNICODE扩充了1024*1024个字符,相应于OO-OF平面,并且将02平面分配给了CJKExtensionB。Microsoft在Windows2000已实现了UTF-16。
Unicode编码布局
0000..007F;BasicLatin
0080..00FF;Latin-1Supplement
0100..017F;LatinExtended-A
0180..024F;LatinExtended-B
0250..02AF;IPAExtensions
02B0..02FF;SpacingModifierLetters
0300..036F;CombiningDiacriticalMarks
0370..03FF;GreekandCoptic
0400..04FF;Cyrillic
0500..052F;CyrillicSupplementary
0530..058F;Armenian
0590..05FF;Hebrew
0600..06FF;Arabic
0700..074F;Syriac
0780..07BF;Thaana
0900..097F;Devanagari
0980..09FF;Bengali
0A00..0A7F;Gurmukhi
0A80..0AFF;Gujarati
0B00..0B7F;Oriya
0B80..0BFF;Tamil
0C00..0C7F;Telugu
0C80..0CFF;Kannada
0D00..0D7F;Malayalam
0D80..0DFF;Sinhala
0E00..0E7F;Thai
0E80..0EFF;Lao
0F00..0FFF;Tibetan
1000..109F;Myanmar
10A0..10FF;Georgian
1100..11FF;HangulJamo
1200..137F;Ethiopic
13A0..13FF;Cherokee
1400..167F;UnifiedCanadianAboriginalSyllabics
1680..169F;Ogham
16A0..16FF;Runic
1700..171F;Tagalog
1720..173F;Hanunoo
1740..175F;Buhid
1760..177F;Tagbanwa
1780..17FF;Khmer
1800..18AF;Mongolian
1E00..1EFF;LatinExtendedAdditional
1F00..1FFF;GreekExtended
2000..206F;GeneralPunctuation
2070..209F;SuperscriptsandSubscripts
20A0..20CF;CurrencySymbols
20D0..20FF;CombiningDiacriticalMarksforSymbols
2100..214F;LetterlikeSymbols
2150..218F;NumberForms
2190..21FF;Arrows
2200..22FF;MathematicalOperators
2300..23FF;MiscellaneousTechnical
2400..243F;ControlPictures
2440..245F;OpticalCharacterRecognition
2460..24FF;EnclosedAlphanumerics
2500..257F;BoxDrawing
2580..259F;BlockElements
25A0..25FF;GeometricShapes
2600..26FF;MiscellaneousSymbols
2700..27BF;Dingbats
27C0..27EF;MiscellaneousMathematicalSymbols-A
27F0..27FF;SupplementalArrows-A
2800..28FF;BraillePatterns
2900..297F;SupplementalArrows-B
2980..29FF;MiscellaneousMathematicalSymbols-B
2A00..2AFF;SupplementalMathematicalOperators
2E80..2EFF;CJKRadicalsSupplement
2F00..2FDF;KangxiRadicals
2FF0..2FFF;IdeographicDescriptionCharacters
3000..303F;CJKSymbolsandPunctuation
3040..309F;Hiragana
30A0..30FF;Katakana
3100..312F;Bopomofo
3130..318F;HangulCompatibilityJamo
3190..319F;Kanbun
31A0..31BF;BopomofoExtended
31F0..31FF;KatakanaPhoneticExtensions
3200..32FF;EnclosedCJKLettersandMonths

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Large language models (LLMs) have the ability to generate smooth and coherent text, bringing new prospects to areas such as artificial intelligence conversation and creative writing. However, LLM also has some key limitations. First, their knowledge is limited to patterns recognized from training data, lacking a true understanding of the world. Second, reasoning skills are limited and cannot make logical inferences or fuse facts from multiple data sources. When faced with more complex and open-ended questions, LLM's answers may become absurd or contradictory, known as "illusions." Therefore, although LLM is very useful in some aspects, it still has certain limitations when dealing with complex problems and real-world situations. In order to bridge these gaps, retrieval-augmented generation (RAG) systems have emerged in recent years. The core idea is

Detailed explanation of the method of converting int type to byte in PHP In PHP, we often need to convert the integer type (int) to the byte (Byte) type, such as when dealing with network data transmission, file processing, or encryption algorithms. This article will introduce in detail how to convert the int type to the byte type and provide specific code examples. 1. The relationship between int type and byte In the computer field, the basic data type int represents an integer, while byte (Byte) is a computer storage unit, usually 8-bit binary data

To solve the problem that jQuery.val() cannot be used, specific code examples are required. For front-end developers, using jQuery is one of the common operations. Among them, using the .val() method to get or set the value of a form element is a very common operation. However, in some specific cases, the problem of not being able to use the .val() method may arise. This article will introduce some common situations and solutions, and provide specific code examples. Problem Description When using jQuery to develop front-end pages, sometimes you will encounter

Correctly displaying Chinese characters in matplotlib is a problem often encountered by many Chinese users. By default, matplotlib uses English fonts and cannot display Chinese characters correctly. To solve this problem, we need to set the correct Chinese font and apply it to matplotlib. Below are some specific code examples to help you display Chinese characters correctly in matplotlib. First, we need to import the required libraries: importmatplot

Known for its powerful performance and versatile features, the iPhone is not immune to the occasional hiccup or technical difficulty, a common trait among complex electronic devices. Experiencing iPhone problems can be frustrating, but usually no alarm is needed. In this comprehensive guide, we aim to demystify some of the most commonly encountered challenges associated with iPhone usage. Our step-by-step approach is designed to help you resolve these common issues, providing practical solutions and troubleshooting tips to get your equipment back in peak working order. Whether you're facing a glitch or a more complex problem, this article can help you resolve them effectively. General Troubleshooting Tips Before delving into specific troubleshooting steps, here are some helpful

The clustering effect evaluation problem in the clustering algorithm requires specific code examples. Clustering is an unsupervised learning method that groups similar samples into one category by clustering data. In clustering algorithms, how to evaluate the effect of clustering is an important issue. This article will introduce several commonly used clustering effect evaluation indicators and give corresponding code examples. 1. Clustering effect evaluation index Silhouette Coefficient Silhouette coefficient evaluates the clustering effect by calculating the closeness of the sample and the degree of separation from other clusters.

Common encoding methods include ASCII encoding, Unicode encoding, UTF-8 encoding, UTF-16 encoding, GBK encoding, etc. Detailed introduction: 1. ASCII encoding is the earliest character encoding standard, using 7-bit binary numbers to represent 128 characters, including English letters, numbers, punctuation marks, control characters, etc.; 2. Unicode encoding is a method used to represent all characters in the world The standard encoding method of characters, which assigns a unique digital code point to each character; 3. UTF-8 encoding, etc.

Unicode is a character encoding standard used to represent various languages and symbols. To convert Unicode encoding to Chinese characters, you can use Python's built-in functions chr() and ord().
