Home > Backend Development > PHP Tutorial > Signature issue of php UTF8 files_PHP tutorial

Signature issue of php UTF8 files_PHP tutorial

WBOY
Release: 2016-07-21 15:43:46
Original
921 people have browsed it

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 any difference. Take the content of the following file (schema.sqlite.sql) as an example:
schema.sqlite.sql

Copy code The code is as follows:

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");

The size of the file is 232 bytes without a signature and 235 bytes with a signature.
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. The program needs to execute the sql through the following statement (php):
Copy the code The code is as follows:

$schemaSql = file_get_contents(dirname(__FILE__) . '/schema.sqlite.sql');
$dbAdapter->getConnection()->exec($schemaSql);

In this case, files with signatures will cause problems, because the "three bytes used for UTF8 signature" are 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/320710.htmlTechArticleThat is, there is BOM format encoding or no BOM format encoding. If you look at the content of the file, you won’t see any difference. Take the content of the following file (schema.sqlite.sql) as an example: schema.sq...
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