Is your php web page garbled_PHP tutorial
Is your php page garbled?
1.
When children’s shoes learning PHP are writing web pages, if they are designing to store Chinese content, a problem that will most likely occur is garbled characters. If the code is generally garbled, we can check three aspects
(1) Whether the web page encoding is correct, such as whether to add the original tag
to the headermeta charset="UTF-8">
(2) Check the default character set used when storing mysql database
(3) Check the encoding of the web page file to see if it is the corresponding Chinese encoding
------------------
Environment: win7 wamp2.2
------------------
2.
Let’s start with 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 based on the results,
1. If the results you display are similar to mine, that is (only character_set_system is encoded as utf8), then please follow the steps below step by step

2. Open the my.ini file, search for the keyword 'mysqld', and after finding it, observe whether there is this line
Character_set_server = utf8
If not, you should add a sentence
below it like I did
3. Search for the keyword 'client' again and see if there is this line
default_character_set = utf8
If not, add
under [client]
4. Save, restart the mysql service, and close the mysql terminal (otherwise the client code you see will not be updated)
5. Open the terminal again and enter
againShow variables like 'char%';
If the following result appears, the mysql data is set successfully

3.
The problem of web page file encoding is the most easily overlooked. This is set when saving the file encoding format.
Solution:
1. Use notepad to open the web page file, and then go to "Format"--"Convert to UTF-8 BOM-free encoding format"

2. Just save it
Problem analysis:
1. I have used it when writing php
"font-size:18px;">'set names utf8'); ?>
But there is still a garbled code problem!
Analysis: Using the above statement, only three items are modified, and these three items are
Character_set_client
Character_set_connection
Character_set_results
And this modification is only temporary, it will be the same as before after closing the terminal
Image description:

2. Let’s analyze the third garbled code problem
(1) Use sublime text3 to edit and open the php file. You can see the encoding information in the lower left corner. You can see that the current encoding is gb2312

(2) When the web page is loaded, it is equivalent to opening a file. The format read at that time is to read the web page file according to the gb2312 encoding. When the user's browser displays it, because the web page declares The character set is utf-8, so the content of the obtained file will be interpreted according to the utf-8 character set, which will cause garbled characters, but there is no problem with the content we read from the database
Web page encoding

Original gbk encoded file

Later UTF-8 encoded files

(3) Please note that sublime text3 does not give you much information when converting the encoding. Although it shows that the conversion is successful, what? The display is still the same, or our notepad is more powerful. How to modify the previous one! After the conversion is successful

3. Why is it that after I modified it as you said, it is still garbled when displayed in the mysql terminal?
Analysis:
(1) Let’s first take a look at what character set is used by cmd under windows?

You can see that the character set of cmd is gbk, which means that any content displayed on the terminal will correspond to the gbk character set, but the Chinese setting of our database is the utf8 character set. When we want to display it, naturally The database data will be read in utf8 encoding. At that time, the encoding was utf-8. Once it reaches the terminal, it will be messed up
(2) How to check?
Just use phpmyadmin, of course you have to set the utf-8 encoding we use!
Note: For more exciting tutorials, please pay attention to Bangkejia Picture and text tutorials channel,

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
