[BOM] UTF8 mysterious coding in PHP

Source: Internet
Author: User

Tip: Do not use NotePad to edit the code file and template file, use a tool that can remove the Unicode signature (BOM) edit. If your website is blank, the style is lost, and the program reports an error, you may have used the tool that failed to remove BOM to modify the template file or source code file.
 
Now, almost all text editing software can display and edit UTF-8-encoded files. However, unfortunately, many of them are not doing well.
Similar to WINDOWS notepad and other software, when saving a file encoded in UTF-8, it inserts three invisible characters (0xEF 0xBB 0xBF, BOM) at the beginning of the file ). It is a string of hidden characters, used for the notepad editor to identify whether the file is encoded in UTF-8. For general files, this will not cause any trouble. However, BOM is a big headache for PHP.
 
PHP does not ignore the BOM. Therefore, when reading, including, or referencing these files, the BOM is used as part of the Beginning body of the file. According to the characteristics of the embedded language, this string of characters will be directly executed (displayed. As a result, even if the top padding of the page is set to 0, the whole web page cannot be placed close to the top of the browser, because there are three characters at the beginning of html!
 
This is not the biggest problem. Due to restrictions of the COOKIE sending mechanism, Cookies cannot be sent to files with BOM at the beginning of these files (because PHP has already sent the file header before the COOKIE is sent ), therefore, the logon and logout functions are invalid. All functions dependent on cookies and sessions are invalid.
 
Therefore, when editing or changing any text files, you must use an editor without adding BOM. The editor in Linux should have no such problem. In WINDOWS, do not use notepad or other editors. Recommended editors are: Editplus version 2.12 and later; EmEditor; UltraEdit (options related to 'add BOM 'need to be removed); Dreamweaver (options related to 'add BOM' need to be removed.
If you want to cancel a file that has been added with BOM, you can use the editor above to save it again. (Editplus needs to be saved as gb first, then as UTF-8 .)
 
In Dreamweaver, you can remove the Unicode signature (BOM), click Modify in the menu bar-> page attribute, or press Ctrl + J.


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.