[BOM] The solution of UTF8 mystery coding problem of PHP program _php Tutorial

Source: Internet
Author: User
Tip: Users with UTF-8 encoding do not use Notepad to edit code files and template files, using tools that can remove the Unicode signature (BOM). If your website opens a blank, the style is lost, the program error is probably you use the tool that failed to remove the BOM to the template file or source code files have been modified.

Now almost all text editing software can display and edit UTF-8 encoded files. Unfortunately, many of these software performance is not ideal.
Software such as Windows-brought Notepad, when saving a UTF-8 encoded file, inserts three invisible characters (0xEF 0xBB 0xBF, or BOM) where the file begins. It is a string of hidden characters that allows editors such as Notepad to identify whether the file is encoded in UTF-8. For general files, this does not cause any trouble. But for PHP, BOM is a * annoying.

PHP does not ignore the BOM, so when you read, include, or reference these files, the BOM is used as part of the text at the beginning of the file. Depending on the characteristics of the embedded language, this string of characters will be executed directly (shown). As a result, even if the top padding of the page is set to 0, there is no way to keep the entire page close to the top of the browser, because there are 3 characters at the beginning of the HTML!

The biggest trouble is not this yet. Limited by the cookie-sending mechanism, where the file has a BOM at the beginning of these files, the cookie cannot be sent out (because PHP has sent the file header before the cookie is sent), so the login and logout functions fail. All the functions that rely on cookies and session implementations are not valid.

Therefore, when editing or changing any text file, be sure to use an editor that does not mess with the BOM. The editor under Linux should not have this problem. Under Windows, do not use editors such as Notepad. The recommended editor is: EditPlus 2.12 or above, Emeditor;ultraedit (need to cancel the "Add BOM" option), Dreamweaver (need to cancel the ' Add BOM ' related options), etc.
For a file that has already been added to the BOM, you can save it with the above editor if you want to cancel it. (EditPlus needs to be saved as GB first and then saved as UTF-8.) )

In Dreamweaver, you can remove the Unicode signature (BOM), click the Edit Page property in the menu bar, or press the Ctrl+j shortcut key directly.


http://www.bkjia.com/PHPjc/478222.html www.bkjia.com true http://www.bkjia.com/PHPjc/478222.html techarticle tip: Users with UTF-8 encoding do not use Notepad to edit code files and template files, using tools that can remove the Unicode signature (BOM). If your website is playing ...

  • Related Article

    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.