Use PHP programming to read Chinese character Lattice Data

Source: Internet
Author: User
Tags character set ord php code php programming

Simplified Chinese national standard font (set in 1981, mainland China ). 7445 characters, including 6773 first-level Chinese characters and 3755 second-level Chinese characters. It is encoded in 2 bytes (16-bit binary.

Location Code: GB2312 indicates that all Chinese characters and symbols of the national standard form a 94 × 94 matrix. In this square matrix, each row is called a "area", and each column is called a "bit". Therefore, this square matrix actually forms a Chinese character set with 94 areas (0 1 to 94 area numbers respectively) and 94 places (bits are 01 to 94) in each area. The area code and location code of a Chinese character are simply combined to form the "location code" of the Chinese character ". In the Chinese character location code, the upper two digits are the area code, and the lower two digits are the bit numbers. It can be seen that the location code corresponds to Chinese characters or symbols one by one.
Internal Code: the internal code of a Chinese character refers to the encoding of a Chinese character in a computer. The inner code is slightly different from the location code. Why not use a location code as the computer code? This is because the range of the Chinese character code and bit code is between 1 and 94. If you directly use the Field Code as the machine internal code, it will conflict with the basic ASCII code.
The inner code of Chinese characters is usually related to the computer system used. Currently, for most computer systems in China, the internal code of a Chinese character occupies two bytes, namely, the high byte and the low byte. The relationship between these two bytes and the location code is as follows: internal Code high = area code A0H (H indicates hexadecimal) internal code low = location code A0H for example, the Chinese character "ah" is "1601 ″, the partition code and bit code are expressed as "1h" in hexadecimal notation respectively, and the inner code is "B0A1H ". B0H indicates the high byte of the inner code, and A1H indicates the low byte of the inner code.

Php code:Returns a string consisting of 0 and 1.
<? Php
* Reading Chinese character Lattice Data
* @ Author legend <>
* @ Link: /? P = 82
* @ Copyright
$ Str = "People's Republic of China ";
$ Font_file_name = "simsun12.fon"; // dot matrix font file name
$ Font_width = 12; // word width
$ Font_height = 12; // The height of a single word
$ Start_offset = 0; // Offset
$ Fp = fopen ($ font_file_name, "rb ");
$ Offset_size = $ font_width * $ font_height/8;
$ String_size = $ font_width * $ font_height;
$ Dot_string = "";
For ($ I = 0; $ I <strlen ($ str); $ I)
If (ord ($ str {$ I})> 160)
// First obtain the location code, and then calculate its position in the location code comment table to obtain the offset of this character in the file.
$ Offset = (ord ($ str {$ I})-0xa1) * 94 ord ($ str {$ I 1})-0xa1) * $ offset_size;
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.