Home > Article > Backend Development > Method to detect and delete page BOM (UTF-8) blank lines_PHP tutorial
We often find that there are some extra blank lines in the page for no reason, but we see it in the editor. We know that this is caused by BOM (UTF-8). Let me share with you some of them. Methods for detecting and deleting BOM (UTF-8).
The picture below is the HTML code seen with firebug after the situation mentioned above occurs.
Figure 1
There is an extra blank line inexplicably, but when we look at the source code, it is not there.
My most common method is to use php to replace
BOM: Universal code file signature BOM (Byte Order Mark, U+FEFF)
The content of the BOM can indicate which encoding UNICODE is, but the received file needs to be disassembled and written into the DB. Seeing the BOM feels a bit ooxx.
In utf8_encode, I saw two programs that can be used to test writing/removing BOM.
Add BOM before the written file content
The code is as follows | Copy code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fwrite($f, pack("CCC", 0xef,0xbb,0xbf)); fwrite($f,$content);
fclose($f);
Use shell in linux system to solve the problem Before discussing in detail the detection and deletion of BOM in UTF-8 encoding, you might as well warm up with an example:
As shown above, the first three bytes are 357, 273, and 277 respectively, which is the octal BOM.
As shown above, the first three bytes are EF, BB, and BF, which is the hexadecimal BOM. Note: The page of a third-party website is used, and there is no guarantee that the example will always be available. When actually doing project development, you may face hundreds or thousands of text files. If a few files are mixed with BOM, it will be difficult to detect. If there is no UTF-8 text file with BOM, you can use vi to make up a few. The relevant commands are as follows: Set UTF-8 encoding:
Add BOM:
Delete BOM:
Query BOM:
How to detect BOM in UTF-8 encoding?
Recommendation: If you use SVN, you can add relevant code to the pre-commit hook to eliminate BOM.
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 Previous article:PHP query ip location (province, city)_PHP tutorialNext article:PHP query ip location (province, city)_PHP tutorial Related articlesSee more |