PHP Programming Please select the correct text editing software _php tips

Source: Internet
Author: User
Tags php programming
If you change any PHP file after:

Cannot log in or log out;
A blank appears at the top of the page;
The top of the page appears with an error warning;
Other abnormal conditions.
Is mostly an editor problem.

This procedure uses UTF-8 code. Almost all text-editing software now can display and edit UTF-8-encoded files. Unfortunately, many of these software are not performing well.

Software such as Notepad, like windows, inserts three invisible characters (0xEF 0xBB 0xBF, or BOM) at the beginning of the file when saving a file encoded in UTF-8. It is a string of hidden characters that allow editors such as Notepad to recognize whether the file is encoded in UTF-8. For general files, this does not cause any trouble. But for PHP, BOM is a big hassle.

The BOM is not ignored by PHP, so when you read, include, or reference the files, the BOM is used as part of the beginning body 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, the entire page cannot be kept close to the front of the browser because there are 3 characters at the beginning of the HTML!

This is not the biggest problem yet. With the restriction of the cookie delivery mechanism, the cookies cannot be delivered in the file with the BOM at the beginning of the file (because PHP has sent the file header before the cookie is sent out), so the login and logout functions fail. All the functionality that relies on cookies and session implementations is invalid.

Therefore, when editing or changing any text file, be sure to use an editor that does not randomly add a BOM. The editor under Linux should not have this problem. Under Windows, do not use editors such as Notepad. The recommended editors are:
EditPlus 2.12 version above;
EmEditor;
UltraEdit (need to cancel the ' Add BOM ' related option);
Dreamweaver (need to cancel the ' Add BOM ' related option)
Wait

For files that have already been added to the BOM, you can save them again with the above editor. (EditPlus need to save as GB first, then save as UTF-8)
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.