Home  >  Article  >  Backend Development  >  How to remove 65279 characters in php

How to remove 65279 characters in php

藏色散人
藏色散人Original
2020-08-22 09:29:001862browse

How to remove 65279 characters in php: first open phpstorm; then select the "remove bom" option in the menu bar file; finally, save the file directly as UTF8 without BOM mode.

How to remove 65279 characters in php

Recommended: "PHP Video Tutorial"

A blank section appears at the top of the HTML page generated by PHP (# 65279 characters) Solution

Recent projects use the ThinkPHP framework, and there is always a small blank space at the top of one of the pages.

As shown in the figure below:

How to remove 65279 characters in php

And it will only appear in chrome and edge browsers, but this problem will not occur in ff. Since the page is spliced ​​together from the PHP HTML template, the html files, JavaScript files, and php files were checked successively. No problems were found.

Using chrome F12, I found that there is a string of  characters in the blank space. Through searching, I learned that this turned out to be a UTF-8 encoding problem.

How to remove 65279 characters in php

The encoding I use is UTF-8 BOM. This encoding method generally appears in Windows operating systems, such as the Notepad and other software that comes with WINDOWS. When saving When a file is encoded in UTF-8, three invisible characters (0xEF 0xBB 0xBF, or BOM) will be inserted at the beginning of the file. It is a string of hidden characters used to let editors such as Notepad identify whether the file is encoded in UTF-8. For ordinary files, this will not cause any trouble. But for PHP, BOM is a big trouble. Because PHP does not ignore the BOM, when reading, including or referencing these files, the BOM will be used as part of the beginning text of the file. According to the characteristics of embedded languages, this string of characters will be executed (displayed) directly.

After knowing the cause of the problem, it can be easily solved. I am using phpstorm. There is a "remove bom" option in the menu bar file, which can be directly saved as UTF-8 without BOM mode. If you use notepad or other tools, you can also select "Save As", and then select "UTF-8 without BOM" in the encoding to solve the problem.

How to remove 65279 characters in php

The above is the detailed content of How to remove 65279 characters in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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