Background knowledge:
Simplified Chinese GB Font (1981-year order, mainland China). 7,445 characters, of which 6,773 Chinese characters, including 3,755 first-level Chinese characters, two-grade Chinese characters 3,008. 2-byte (16-bit binary) encoding is used.
Location Code: GB GB2312 stipulates that all GB characters and symbols form a 94x94 matrix. In this phalanx, each row is called a "zone", and each column is called a "bit", so the Phalanx actually consists of a Chinese character set with 94 areas (0 1 to 94 respectively) and 94 digits in each region (the digits are 01 to 94 respectively). The area code of a Chinese character is composed of a simple combination of the region code and the digit number. In the location code of Chinese characters, the high two-bit is the area code, and the low two digit is the bit number. This shows that the location code and Chinese characters or symbols are one by one corresponding.
Inner code: Chinese characters in the code refers to the computer to represent the encoding of Chinese characters. The internal code is slightly different from the location code. Why not use location code directly as the code inside the computer? This is because the region code of Chinese characters and the range of bit code within 1 to 94, if the direct use of location code as the internal code, will be in conflict with the basic ASCII code. The inner code of Chinese characters is usually related to the computer system used. At present, for most computer systems in China, the inner code of a Chinese character occupies two bytes, called High byte and low byte respectively, and the two-bit byte and location code of the relationship is as follows: Inside code high = region code a0h (h for hexadecimal) inner code low = bit code A0H For example, Chinese characters "ah" The Location code for "1601″", The region code and the bit code are "1001H" in hexadecimal notation respectively, 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.
PHP Code: Returns a string consisting of 0 and 1.
<?php
/**
* Read Chinese character dot matrix 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 evaluated, and then the position in the two-dimensional table of the location code is computed, and then the deviation of the character in the file is obtained.
$offset = ((Ord ($str {$i})-0xa1) * 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)
{
Converts binary lattice data to a string
$dot _string. = sprintf ("B", Ord ($bindot {$j}));
}
}
Fclose ($FP);
echo $dot _string;
?>