Solution to the problem that the PHP page content is not centered: 1. Place the include file in the head; 2. Save the PHP file in UTF-8 encoding and cancel the Unicode signature.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to solve the problem that the content of the php page is not centered ?
PHP-After introducing the file (include), the page is misaligned and not centered. Solution
1. Put the include file in the head, not on html or doctype, so The centering problem can be solved. If there is a blank line, you can use
to include the include file, but this is not a fundamental solution.2. The fundamental solution is to open the included file with DW, modify the toolbar--> Page Properties-> Title Encoding-> and remove the check box in front of Include Unicode Signature (BOM)
In this case, no matter where it is included, there will be no such problem. Of course, it can also be removed using other editors.
Find the reason:
Analyze the reason:
When the file is saved in UTF-8 encoding, there are two situations: with Unicode signature (BOM) and without Unicode signature . The BOM information is a string of hidden characters at the beginning of the file, which is used to allow some editors to recognize that this is a UTF-8 encoded file.
But for PHP, PHP did not consider the BOM issue when designing. It will not ignore the three characters of the BOM at the beginning of the UTF-8 encoded file, and will use the BOM as part of the text at the beginning of the file. . Since the code after or
Because there are these three characters at the beginning of html, even if the top padding of the page is set to 0, the entire web page cannot be placed close to the top of the browser. Due to limitations of the COOKIE sending mechanism, in files that already have a BOM at the beginning of these files, the COOKIE cannot be sent (because PHP has already sent the file header before the COOKIE is sent), so the login and logout functions fail. All functions that rely on COOKIE and SESSION are invalid.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve the problem that the content of the php page is not centered. For more information, please follow other related articles on the PHP Chinese website!