Is your php webpage garbled. Is your php webpage garbled? 1. when you are writing a webpage for learning php, most of the problems that may occur when you design Chinese content for storage. Is your php webpage garbled?
I,
When writing web pages, when designing Chinese content for storage, most of the problems may be garbled. If the code is garbled, we can check three aspects.
(1) whether the webpage code is correct, for example, whether to add the original tag to the header
Meta charset = "UTF-8">
(2) Check the default character set used for mysql database storage
(3) Check whether the webpage file is encoded in Chinese.
------------------
Environment: win7 + wamp2.2
------------------
II,
Next we will start from the second point, the encoding character set used by the mysq database
(1) open the mysql terminal, view the current settings, and determine the scope to be modified
Show variables like 'char % ';
(2) analyze the results,
1. if the result you show is similar to mine (only character_set_system is encoded as utf8), follow the steps below.
2. open the my. ini file and search for the keyword 'mysqld'. find the keyword and check whether this line exists.
Character_set_server = utf8
If not, add a sentence below it like me
3. search for the keyword 'client' again to see if this line exists.
Default_character_set = utf8
If not, add it under [client ].
4. save, restart the mysql service, and close the mysql terminal (otherwise the client code will not be updated)
5. open the terminal again and enter
Show variables like 'char % ';
If the following result is displayed, mysql data is successfully set.
III,
The problem of webpage file encoding is the easiest to ignore. this is set when saving the file encoding format.
Solution:
1. Use notepad ++ to open the webpage file, and then in the "format" -- "convert to UTF-8 without BOM encoding format"
2. just save it.
Problem analysis:
1. I have used php before.
"Font-size: 18px;"> 'set names utf8');?>
But there is still a garbled problem!
Analysis: when the preceding statement is used, only three items are modified.
Character_set_client
Character_set_connection
Character_set_results
In addition, this modification is only temporary. after the terminal is closed, it is the same as the original one.
Image description:
2. let's analyze the third garbled problem
(1) use sublime text3 to edit and open the php file. We can see the encoding information in the lower left corner. we can see that the current encoding is gb2312.
(2) when a webpage is loaded, it is equivalent to opening a file. at that time, the webpage file is read in the format of gb2312, while the webpage file is displayed in the browser, because the webpage declares that the character set is UTF-8, the obtained file will be interpreted according to the UTF-8 character set. this will cause garbled characters, while the content we read from the database is no problem.
Webpage code
Original gbk-encoded file
Later, UTF-8 encoded files
(3) note that the conversion code of sublime text3 is not quite for you. although the conversion is successful, what about it? The display is still the same. we still use notepad ++ to make some effort. how can we modify the front! After successful conversion
3. Why do I display the changes in the mysql terminal with garbled characters?
Analysis:
(1) Let's take a look at the character set used by cmd in windows?
We can see that the cmd character set is gbk, that is to say, any content displayed on the terminal will correspond to the gbk character set. However, when we want to display the utf8 character set in the Chinese language of our database, naturally, the database data will be read in utf8 encoding. at that time, the encoding is UTF-8, and it will be messy once it reaches the terminal.
(2) How can I view it?
You can use phpmyadmin. of course you must set the UTF-8 encoding!
Note: For more exciting tutorials, please follow the help HouseGraphic tutorialChannel,
Tips 1. when writing a web page, when designing a Chinese content storage, most of the problems that may occur are garbled characters. General garbled characters...