_php techniques for signing problems in PHP UTF8 files

Source: Internet
Author: User
Tags create index sqlite
That is, there is a BOM format code, or no BOM format coding.
If you look at the contents of a document and you do not see any difference, take the following document (Schema.sqlite.sql) as an example:
Schema.sqlite.sql
Copy Code code as follows:

CREATE TABLE Guestbook (
ID INTEGER not NULL PRIMARY KEY AutoIncrement,
Email VARCHAR not NULL DEFAULT ' noemail@test.com ',
Comment TEXT NULL,
Created DATETIME not NULL
);
CREATE INDEX "id" on "Guestbook" ("id");

If you do not have a signature, the file size is 232 bytes, and 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.
In general, the presence or absence of a signature does not cause problems because the editor or other software can infer whether it is UTF8 according to the contents of the text.
But sometimes it can lead to problems, such as appeal documents. The file is an SQL statement file that the program will execute precisely through the following statement (PHP):
Copy Code code as follows:

$SCHEMASQL = file_get_contents (dirname (__file__). '/schema.sqlite.sql ');
$dbAdapter->getconnection ()->exec ($SCHEMASQL);

In this case, a signed file can cause problems because the "three bytes of UTF8 signature" is actually at the front of the file. As a result, the above statement cannot run successfully.
The solution is also very simple, remove the file UTF8 signature.
Of course, the contents of the above file are in fact single-byte, there is no need to save for UTF8 encoding.

Supplemental: All Single-byte content files are the default encoding of the system unless you add a UTF8 signature, or you open the file again.

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.