PHP read the lattice data of Chinese characters, PHP reading dot matrix _php Tutorial

Source: Internet
Author: User
Tags ord

PHP reads the bitmap data of Chinese characters, PHP reads the dot matrix


Problems encountered in the project:

How does PHP read the bitmap data of Chinese characters? If you want to enter a paragraph of text, you can get all the dot-matrix codes for this paragraph.

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

<?php/*** 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; Word height $start_offset = 0; Offset $fp = fopen ($font _file_name, "RB"), $offset _size = $font _width * $font _height/8; $string _size = $font _width * $font _h eight; $dot _string = ""; for ($i = 0; $i < strlen ($STR); $i + +) {if (ord ($str {$i}) > 160) {//Seek the Location code first, then calculate its position in the two-dimensional table of the location code, and then derive 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 _si Ze $j + +) {//convert binary bitmap data to string $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/1020542.html www.bkjia.com true http://www.bkjia.com/PHPjc/1020542.html techarticle PHP reads the lattice data of Chinese characters, PHP reads the problems encountered in the lattice project: How does PHP read the lattice data of Chinese characters? Want to implement input a paragraph of text, can get all the points of this paragraph of text ...

  • 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.