Table of Contents
PHP reads the lattice data of Chinese characters, php reads the lattice
Home Backend Development PHP Tutorial PHP reads the lattice data of Chinese characters, php reads the lattice_PHP tutorial

PHP reads the lattice data of Chinese characters, php reads the lattice_PHP tutorial

Jul 13, 2016 am 09:49 AM
php

PHP reads the lattice data of Chinese characters, php reads the lattice

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 bitmap 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. Using 2-byte (16-bit binary) encoding.

Location code: The 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 to 1 to 94), 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. Currently, 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, and 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

<&#63;php
/**
* 读取汉字点阵数据
*
*/

$str = "中华人民共和国";

$font_file_name = "simsun12.fon"; // 点阵字库文件名
$font_width = 12; // 单字宽度
$font_height = 12; // 单字高度
$start_offset = 0; // 偏移

$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)
{
// 先求区位码,然后再计算其在区位码二维表中的位置,进而得出此字符在文件中的偏移
$offset = ((ord($str{$i}) - 0xa1) * 94 + ord($str{$i + 1}) - 0xa1) * $offset_size;
$i ++;
}
else
{
$offset = (ord($str{$i}) + 156 - 1) * $offset_size;
}

// 读取其点阵数据
fseek($fp, $start_offset + $offset, SEEK_SET);
$bindot = fread($fp, $offset_size);

for ($j = 0; $j < $offset_size; $j ++)
{
// 将二进制点阵数据转化为字符串
$dot_string .= sprintf("%08b", ord($bindot{$j}));
}
}

fclose($fp);

echo $dot_string;
&#63;>
Copy after login

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1020542.htmlTechArticlePHP reads the lattice data of Chinese characters. Problems encountered in the php reading lattice project: How to read with PHP Get the lattice data of Chinese characters? If you want to input a piece of text, you can get all the points of this piece of text...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

See all articles