Home>Article>Backend Development> How to read dot matrix data of Chinese characters in PHP
This article mainly introduces how PHP reads the lattice data of Chinese characters. Interested friends can refer to it. I hope it will be helpful to everyone.
Solution:
The simplified Chinese national standard font library has 7445 characters, including 6773 Chinese characters, including 3755 first-level Chinese characters and 3008 second-level Chinese characters. Using 2-byte (16-bit binary) encoding.
Location code: National standard GB2312 stipulates that all national standard Chinese characters and symbols 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 94-area area (area numbers are 0 to 1 to 94), each There are 94 digits (digit numbers are 01 to 94) of Chinese character sets in the area. The area code and location number of a Chinese character are simply combined to form the "location code" of the Chinese character. In the area code of Chinese characters, the upper two digits are the area code and the lower two digits are the position number. It can be seen that there is a one-to-one correspondence between location codes and Chinese characters or symbols.
Internal code: The internal code of Chinese characters refers to the encoding of Chinese characters in computers. The in-machine code is slightly different from the location code. Currently, for most computer systems in China, the internal code of a Chinese character occupies two bytes, which are called high-order byte and low-order byte respectively, and the relationship between these two bytes and the area code is as follows: Internal code high-order = area Code A0H (H represents hexadecimal) The low digit of the inner code = bit code A0H. For example, the area code of the Chinese character "ah" is "1601", and the area code and bit code are expressed in hexadecimal respectively as "1001H", then Its internal code is "B0A1H". Among them, B0H is the high-order byte of the internal code, and A1H is the low-order byte of the internal code.
Return a string composed of 0 and 1
160) { // 先求区位码,然后再计算其在区位码二维表中的位置,进而得出此字符在文件中的偏移 $offset = ((ord($str{$i}) - 0xa1) * 94 + ord($str{$i + 1}) - 0xa1) * $offset_size; $i ++; } else { $offset = (ord($str{$i}) + 156 - 1) * $offset_size; } // 读取其点阵数据 fseek($fp, $start_offset + $offset, SEEK_SET); $bindot = fread($fp, $offset_size); for ($j = 0; $j < $offset_size; $j ++) { // 将二进制点阵数据转化为字符串 $dot_string .= sprintf("%08b", ord($bindot{$j})); } } fclose($fp); echo $dot_string; ?>
Summary:The above is the entire content of this article, I hope it will be helpful to everyone's learning.
Related recommendations:
php recursive traversal to achieve unlimited classification
PHP method to implement ring queue based on memcache
The above is the detailed content of How to read dot matrix data of Chinese characters in PHP. For more information, please follow other related articles on the PHP Chinese website!