The impact of UTF-8 BOM on PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:27:28
Original
736 people have browsed it

When I was writing code with notepad++ today, after loading a frameset frame template, the page was not displayed on the page. After checking the source code, it was normal. Then I simply deleted everything inside and just wrote a few test words and it displayed normally.

After struggling for a long time, I finally saw that there are two PHP files with different control templates. One is encoded in UTF-8 without BOM and the other is encoded in UTF-8 format. Try to use the UTF-8 format. has been changed to UTF-8 BOM-free format. Then save and open firefox, the frameset template that was not displayed before is actually displayed. Then I tried it under chrome and it still didn't display. Then I thought about whether there were other PHP files whose formats had not been converted to BOM-free format. After checking, I changed all the UTF-8 files to UTF-8 BOM-free format. After saving, Chrome can display it normally. Finally breathed a sigh of relief.

I didn’t pay much attention to UTF-8 and UTF-8 BOM-free formats before. So I checked on Baidu to see what the differences are between them. It's roughly as follows:

UTF-8 encoded files can be divided into two formats: no BOM and BOM.

What is BOM? "EF BB BF" These three bytes are called BOM, and the full name of BOM is "Byte Order Mard". BOM is commonly used in UTF-8 files to indicate that the file is a UTF-8 file, and the original meaning of BOM is used to represent high and low byte sequences in UTF16. There is a BOM before the byte stream, which means that the low byte sequence is used (the low byte is in front), and utf8 does not need to consider the byte sequence, so in fact, it does not matter whether there is a BOM or not. UTF-8 uses bytes as the encoding unit and has no endianness issues. UTF-16 uses two bytes as the encoding unit. Before interpreting a UTF-16 text, you must first understand the byte order of each encoding unit. For example, the Unicode encoding of "Kui" received is 594E, and the Unicode encoding of "B" is 4E59. If we receive the UTF-16 byte stream "594E", is this "Ku" or "B"?

If you choose to use BOM when saving the file, the page will not display properly. Generally speaking, php does not support BOM. PHP files should be saved as UTF-8 BOM-free type

So when saving UTF8 encoded PHP files, do not use BOM.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/819539.htmlTechArticleWhen I was writing code with notepad++ today, after loading a frameset frame template, the page was not displayed on the page. Check it out Everything is normal after source code. Then I simply deleted everything inside and wrote whatever I wanted...
Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!