PHP reads dot matrix data of Chinese characters, php reads dot matrix _ PHP Tutorial

Source: Internet
Author: User
PHP reads dot matrix data of Chinese characters and php reads dot matrix data. PHP reads the dot matrix data of Chinese characters, and php reads the dot matrix data of Chinese characters: how does PHP read the dot matrix data of Chinese characters? To input a piece of text, you can get all the points of the text. PHP reads the dot matrix data of Chinese characters and php reads the dot matrix data.

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.

<? Php/*** READ Chinese character Dot matrix data **/$ str = "People's Republic of China"; $ font_file_name = "simsun12.fon"; // the file name of the dot matrix font $ 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) {// Obtain the location code first, then, calculate the position of the character in the partition code two table to 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 dot matrix data to a string $ 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.

The problem encountered in the Ghost Project: How does PHP read dot matrix data of Chinese characters? To input a paragraph of text, you can get all vertices of the paragraph...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.