PHP reads dot matrix data of Chinese characters. This article describes how to use PHP to read the dot matrix data of Chinese characters. Project PHP reads dot matrix data of Chinese characters
This article describes in detail how to use PHP to read dot matrix data of Chinese characters.
Problems encountered in the project:
How does PHP read dot matrix data of Chinese characters? To input a paragraph of text, you can get all the dot matrix codes of the paragraph.
Solution:
The simplified Chinese national standard font contains 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. 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 = bit 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.
Returns a string consisting of 0 and 1.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/** * Reading Chinese character Lattice Data * */ $ 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; $ I ++; } Else { $ Offset = (ord ($ str {$ I}) + 156-1) * $ offset_size; } // Read its dot matrix data Fseek ($ fp, $ start_offset + $ offset, SEEK_SET ); $ Bindot = fread ($ fp, $ offset_size ); For ($ j = 0; $ j <$ offset_size; $ j ++) { // Convert binary dot matrix data into strings $ Dot_string. = sprintf ("% 08b", ord ($ bindot {$ j })); } } Fclose ($ fp ); Echo $ dot_string; ?> |
The above is all the content of this article. I hope you will like it.
This article describes in detail how to use PHP to read the dot matrix data of Chinese characters. it is very practical. if you need it, you can refer to it. Project...