Home > Backend Development > PHP Tutorial > Signature issues and solutions for UTF8 files_PHP tutorial

Signature issues and solutions for UTF8 files_PHP tutorial

WBOY
Release: 2016-07-21 14:55:43
Original
955 people have browsed it

When we save the UTF8 text file, we can choose to have it signed or not. That is, there is BOM format encoding, or there is no BOM format encoding. If you look at the content of the file, you won’t see any difference. Take the following file (schema.sqlite.sql) as an example:

CREATE TABLE guestbook (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
email VARCHAR(32) NOT NULL DEFAULT 'noemail@test.com',
comment TEXT NULL,
created DATETIME NOT NULL
);

CREATE INDEX "id" ON " guestbook" ("id");

If not signed, the file size is 232 bytes, if signed, the file size is 235 bytes.

The UTF8 signature has 3 bytes (content: EFBBBF), which is specifically used to tell the software that the file is UTF8 encoded.

Under normal circumstances, whether there is a signature or not will not cause problems, because the editor or other software can infer whether it is UTF8 based on the content of the text.

But sometimes it can still cause problems, such as appeal documents. This file is a sql statement file, and the program needs to execute the sql through the following statement (php):

$schemaSql = file_get_contents(dirname(__FILE__) . '/schema.sqlite.sql');

$dbAdapter->getConnection()->exec($schemaSql);

In this case, signed files will cause problems because "UTF8 signature uses three Bytes" is actually located at the front of the file. As a result, the above statement cannot run successfully.

The solution is also very simple, just remove the UTF8 signature of the file.

Of course, the contents of the above files are actually single-byte, and there is no need to save them in UTF8 encoding.

Supplement: Unless a file with single-byte content is added with a UTF8 signature, the system's default encoding will still be used when the file is opened again.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364391.htmlTechArticleWhen we save a UTF8 text file, we can choose to have it signed or not. That is, there is BOM format encoding, or there is no BOM format encoding. If you look at the content of the file, you can’t see...
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