Table of Contents
Is your php page garbled?
Home Backend Development PHP Tutorial Is your php web page garbled_PHP tutorial

Is your php web page garbled_PHP tutorial

Jul 13, 2016 am 09:48 AM
php one Garbled characters ? exist study of write Web page design

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 header

meta 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

again

Show 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,

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1022667.htmlTechArticleIs your php webpage garbled? 1. Children's shoes for learning php When writing webpages, if the Chinese content is designed When storing, a problem that often occurs is garbled characters. General gibberish...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

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

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

See all articles