PHP UTF8 File Signature Problem _php tutorial

Source: Internet
Author: User
That is, the BOM format code, or no BOM format encoding.
If you look at the contents of the document, there is no difference, take the following document (Schema.sqlite.sql) as an example:
Schema.sqlite.sql
Copy CodeThe code is 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) and is specifically used to tell the software that the file is UTF8 encoded.
In general, there is no problem with unsigned signatures, as the editor or other software can infer whether or not it is UTF8 according to the content of the text.
But sometimes it can cause problems, such as appeal documents. The file is an SQL statement file, and the program executes the SQL in exactly the following statement (PHP):
Copy CodeThe code is as follows:
$SCHEMASQL = file_get_contents (dirname (__file__). '/schema.sqlite.sql ');
$dbAdapter->getconnection ()->exec ($SCHEMASQL);

In this case, the file with the signature causes a problem because the "three bytes used for the UTF8 signature" is actually at the front of the file. This causes the above statement to fail to run successfully.
The solution is also very simple, remove the file UTF8 signature can be.
Of course, the contents of the above files are actually single-byte, it is not necessary to save the UTF8 encoding.

Add: Files that are all single-byte content unless you add a UTF8 signature, or the system's default encoding when you open the file again.

http://www.bkjia.com/PHPjc/320710.html www.bkjia.com true http://www.bkjia.com/PHPjc/320710.html techarticle that is, the BOM format code, or no BOM format encoding. If you look at the contents of the file, there is no difference, the following document (Schema.sqlite.sql) as an example: schema.sq ...

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