PHP reads lattice data of Chinese characters_PHP tutorial

WBOY
Release: 2016-07-13 09:49:13
Original
916 people have browsed it

PHP reads the dot matrix data of Chinese characters

This article gives you a detailed description of the methods and examples of using PHP to read the dot matrix data of Chinese characters. It is very practical and necessary. Friends can refer to it.

Problems encountered in the project:

How to read the lattice data of Chinese characters in PHP? If you want to input a piece of text, you can get all the lattice codes of this piece of text.

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. Use 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 1 to 94 respectively), 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. At present, 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. 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.

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

/**

* Read Chinese character dot matrix data

*

*/

$str = "People's Republic of China";

$font_file_name = "simsun12.fon"; // Dot matrix font file name

$font_width = 12; // Single word width

$font_height = 12; // Single font 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)

{

// First find the location code, and then calculate its position in the two-dimensional table of location codes, and then get 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 lattice data

fseek($fp, $start_offset $offset, SEEK_SET);

$bindot = fread($fp, $offset_size);

for ($j = 0; $j < $offset_size; $j )

{

// Convert binary lattice data into string

$dot_string .= sprintf(" b", ord($bindot{$j}));

}

}

fclose($fp);

echo $dot_string;

?>

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1020277.htmlTechArticlePHP reads the dot matrix data of Chinese characters. This article tells you in detail how to use PHP to read the dot matrix data of Chinese characters. The methods and examples are very practical, friends in need can refer to them. Project...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template