PhpUTF8 File signature

Source: Internet
Author: User
When saving the UTF8 text file, you can choose to include a signature or not. That is, BOM format encoding is available, or BOM format encoding is not available.
If you can see no difference in the content of the file, the content of the following column File (schema. sqlite. SQL) is used as an example:
Schema. sqlite. SQL

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


If no signature is required, the file size is 232 bytes. If yes, the file size is 235 bytes.
The UTF8 signature contains three bytes (the content is EFBBBF). it is used to tell the software that the file is UTF-8 encoded.
In general, there is no signature, because the editor or other software can infer whether it is UTF8 based on the content of the text.
But sometimes it may cause problems, such as appeal files. This file is an SQL statement file. The program uses the following statement (php) to execute the SQL statement:

The 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 will cause problems, because "the three bytes used for UTF8 signature" is located at the beginning of the file. Therefore, the preceding statement cannot be run successfully.
The solution is also simple. remove the UTF8 signature of the file.
Of course, the content of the above files is actually single-byte and there is no need to save it as UTF-8 encoding.

Supplement: All files with single-byte content are the default encoding of the system when the file is opened again unless the UTF-8 signature is added.

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.