PHP reads the lattice data of Chinese characters
This article describes in detail the use of PHP reading Chinese characters of the lattice data method and example, very practical, the need for small partners can refer to.
Problems encountered in the project:
How does PHP read the lattice data of Chinese characters? If you want to enter a text, you can get all the dot-matrix codes for this section of text.
Workaround:
Chinese national standard font 7,445 characters, of which 6,773 Chinese characters, including a first-level Chinese characters 3,755, two-level kanji 3,008. Encoded with 2-byte (16-bit binary).
Location Code: GB GB2312 provisions, all the national standard Chinese characters and symbols constitute a 94x94 matrix. In this matrix, each row is called a "zone", each column is called a "bit", so the square actually consists of a 94-zone (area code of 0 1 to 94), each region has 94 bits (01 to 94 of the number of digits) of the character set. The area code of the Chinese character is composed of a simple combination of the region code and the digit number. In the location code of Chinese characters, the height of two digits is the area code, and the lower two bits is the number. Thus, the location code and the Chinese characters or symbols are one by one corresponding.
Inner code: The inner code of Chinese characters refers to the encoding of Chinese characters in the computer. There is a slight difference between the in-machine code and the location code. At present, for most of the domestic computer systems, a Chinese character in the internal code accounted for two bytes, respectively called high-order byte and low byte, and the relationship between the two-bit byte and location code is as follows: Inner code high = area code +a0h (h for hexadecimal) code low = bit code +A0H For example, the location code of "Ah" is "1601″ , the area code and the bit code are hexadecimal means "1001H", then its inner code is "b0a1h". Where b0h is the high byte of the inner code, A1H is 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 21st 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 |
/** * Read Chinese character lattice data * */ $str = "People's Republic of China"; $font _file_name = "Simsun12.fon"; Bitmap font file name $font _width = 12; Word width $font _height = 12; Word height $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) { The location code is first obtained, then the position in the two-dimensional table of location code is calculated, and then the offset of this character in the file is obtained. $offset = ((Ord ($str {$i})-0XA1) * 94 + ord ($str {$i + 1})-0xa1) * $offset _size; $i + +; } Else { $offset = (Ord ($str {$i}) + 156-1) * $offset _size; } Reading its lattice data Fseek ($fp, $start _offset + $offset, seek_set); $bindot = Fread ($fp, $offset _size); for ($j = 0; $j < $offset _size; $j + +) { Converting binary lattice data to strings $dot _string. = sprintf ("%08b", Ord ($bindot {$j})); } } Fclose ($FP); echo $dot _string; ?> |
The above mentioned is the whole content of this article, I hope you can like.
http://www.bkjia.com/PHPjc/1020277.html www.bkjia.com true http://www.bkjia.com/PHPjc/1020277.html techarticle php read the dot matrix data of Chinese characters This article tells you in detail the use of PHP reading Chinese characters of the lattice data method and example, very practical, the need for small partners can refer to. Project ...