BOM Header Issues

Source: Internet
Author: User

Recently there are many on the micro-blog to discuss the BOM head problem, BOM header will cause the page display garbled, XML analysis problems. And I happen to encounter a situation in the WML page if the BOM header, PC Browser (IE, Firefox) and Mobile browser (UC) are normal, and if the BOM header, the phone is normal, the PC side is not normal. For this reason, the BOM head and coding do some simple research.

  

1, what is the BOM header

For Notepad that uses Windows to edit text, when saved with UTF-8 encoding, the text is added three invisible bytes 0xEF 0xBB 0xBF, some articles refer to these three bytes as three characters is wrong, in fact, if the three bytes decoded according to UTF-8, Represents a character, this character is not displayed, and is different from the space, let's first convert the three bytes into a

Coding UTF8 Encoding 16 binary Unicode encoding 16 binary Unicode encoding 10 binary
Value Efbbbf FEFF 65279

  

Check out the tool for viewing Chinese characters on the Web by Encoding (http://www.mytju.com/classcode/tools/encode_utf8.asp)

  

  

As you can see, this is a character without any display, so what is the use of such a character? In fact, this character is used by the Windows text Editor as a token of character encoding, under Windows System, once the first three bytes of text is found to be EFBBBF, then the entire text is confirmed to be encoded according to Utf-8.

2, the general process of BOM head

  A, Linux to see if the file has a BOM header method

A typical Linux server has a XXD command that can be opened as a 16-binary view.

  b, see which files under the project have BOM header

Many methods, online generally provide grep-r-i-l $ ' ^\xef\xbb\xbf './That is, under a project, the loop project inside the file, not case-sensitive, to see whether it has a hex under the EFBBBF beginning of the file, output file name information

  C, remove BOM head

Single file removal BOM head can be opened with VI file, set Nobomb after saving can be removed, the same way if you want to add BOM head, set bomb can, and if you remove all of the items that exist in the BOM header files, generally need to write scripts to implement, under PHP
A1, looping through each file
B1, using substr () to view the first three bytes of a file, turn bytes into decimal view
"EF" = 239
"BB" = 187
"BF" = 191
C1, if you see the first three bytes is the BOM header, then substr () after the interception of text written


BOM Header Issues

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.