Detailed explanation of the BOM header and the method of removing the BOM header

Similar to the Notepad and other software that comes with WINDOWS, when saving a file encoded in UTF-8, three invisible characters (0xEF 0xBB 0xBF, or BOM) will be inserted at the beginning of the file. It is a hidden string of characters used to let editors such as Notepad recognize whether the file is encoded in UTF-8. For normal files, this shouldn't cause any trouble. But for PHP, BOM is a big hassle.

  PHP does not ignore the BOM, so when reading, including, or referencing these files, the BOM is included as part of the text at the beginning of the file. According to the characteristics of the embedded language, this string of characters will be executed (displayed) directly. As a result, even if the top padding of the page is set to 0, it is impossible to make the entire web page close to the top of the browser, because there are these 3 characters at the beginning of html!

     If the window editor is saved as a utf8 file, it will help you add a BOM header to tell other editors to display characters in utf8

But there is no need to add BOM header recognition on the web page, because the web page can use the head header to specify charset=utf8 to tell the browser to use utf8 to interpret. But you use the window's automatic editor, edit, and then display it on the web page. The 3 characters 0xEF 0xBB 0xBF are displayed.

 

Solution: 0xEF 0xBB 0xBF needs to be removed on the web page, you can use editplus to select the encoding without BOM, so you can remove it

1: The method of editplus to BOM header

After the editor is adjusted to UTF8 encoding format, there will be a string of hidden characters (that is, BOM) in front of the saved file, which is used by the editor to identify whether the file is encoded in UTF8. Run Editplus, click Tools, select Preferences, select the file, select the UTF-8 logo to always delete the signature, and then edit and save the PHP file without BOM;

2. Ultraedit remove bom head method

After opening the file, select the encoding format of the save as option (utf-8 without bom header), and confirm it is ok

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324991832&siteId=291194637