Home > Article > Backend Development > The solution to the problem of garbled characters when opening the website PHP. The solution to the nsis error. The solution to the win7 black screen. The solution to the Dragon Valley error report.
Problem: Open the written php file with a browser, and then find that Chinese characters are displayed as question marks, and the website is not displayed properly
Reason: The reason for the garbled code problem is that the encoding methods used by the database, browser and php file are different
Solution:
1. Modification of browser encoding method: (Take Google Chrome as an example)
The three horizontal lines in the upper right corner of the page - click to enter - more tools - encoding. Select the encoding method. Here I choose utf8
2. Modification of php files:
<code><span><<span>meta</span><span>http-equiv</span>=<span>"Content-Type"</span><span>content</span>=<span>"text/html; charset=utf8"</span> /></span></code>
The encoding method of the file header is changed to utf8
3. Modification of mysql database (taking wamp as an example)
(1) Enter the mysql console, enter the password, and press Enter. At this time, the following welcome message will appear
<code> Enter password: **** Welcome <span>to</span><span>the</span> MySQL monitor. Commands <span>end</span><span>with</span> ; <span>or</span> \g. Your MySQL connection <span>id</span><span>is</span><span>2</span> Server <span>version</span>: <span>5.7</span><span>.9</span> MySQL Community Server (GPL)</code>
(2) Enter
<code><span><span>show</span> variables <span>like</span><span>'%char%'</span>;</span>//注意分号</code>
and the current encoding method will be displayed. The default is gbk
(3) Search for my.ini in the wamp installation directory, and then open it as a text document
(4) Add
<code><span>default</span>-character-<span>set</span>=utf8</code>
under [client] (5) Add
<code><span>default</span>-character-<span>set</span>=utf8</code>
under [mysql] (6) Add
<code>character_<span>set</span>_server=utf8</code>
under [mysqld] (7) Save the changes, restart the server, and you can open it again at this time The mysql console confirms the encoding format
At this point, the encoding formats of the database, browser and php files are already the same, and the problem of Chinese displaying garbled characters will no longer occur.
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });The above introduces the solution to the garbled problem when opening the website PHP, including the solution and PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.