What to do if dw php web page has Chinese garbled characters?
dw Solution to garbled Chinese characters in php web pages: 1. Set the title encoding to UTF8; 2. When using Dreamweaver to create a new php file, declare the format utf through "
" -8; 3. Set the MYSQL connection encoding through "mysql_query("SET NAMES GBK");". ="utf-8">

The operating environment of this tutorial: Windows 7 system, Dreamweaver version 8, Dell G3 computer.
What should I do if the dw php webpage has Chinese garbled characters?
How to solve the problem of Chinese garbled characters in the preview interface of Dreamweaver when running the php file
Doing website development requires dealing with different problems in many countries As for language, we often encounter a mix of Chinese and English. When using Dreamweaver to create and run PHP code, the Chinese preview window sometimes displays garbled characters, but English can be displayed normally.


1. File encoding: refers to the encoding in which the page file (.html, .php, etc.) itself is saved. Notepad and Dreamweaver will automatically recognize the file encoding when opening the page, so there will be less problems. However, ZendStudio does not automatically recognize the encoding. It will only open the file with a certain encoding. If you accidentally open the file with the wrong encoding while working, and save it after making the modification, garbled characters will appear.
Solution: Page settings, title/encoding, set to UTF8

2, page Declaration encoding:
HTML page encoding settingsIn the HTML code HEAD, it can be used to tell the browser what encoding the web page uses. Currently, XXX mainly uses GB2312 and UTF in Chinese website development -8 Two encodings. When using Dreamweaver to create a new php file, you need to declare the format utf-8:

1. The database uses UTF8 encoding, and the page declaration encoding is GB2312. This is the most common cause of garbled characters.
At this time, the directly SELECT data in the PHP script will be garbled. You need to use it before querying: mysql_query("SET NAMES GBK"); to set the MYSQL connection encoding to ensure that the page declaration encoding is consistent with the setting here. The specified connection encoding is consistent (GBK is an extension of GB2312). If the page is UTF-8 encoded, you can use: mysql_query("SET NAMES UTF8");
PHP encoding setting
Write the first sentence in the php code:
<?php
header("Content-type:text/html;charset=utf-8");
?>Modify the php.ini file
Modify "/etc/php5/apache2/php.ini" and change
default_charset = "iso-8859-1"
to default_charset = "utf-8"
Mysql encoding settings
<?php mysql_query('SET NAMES UTF8'); ?>
Note that it is UTF8 instead of the commonly used UTF-8. If the encoding of the page declaration is consistent with the internal encoding of the database, you do not need to set the connection encoding.
The data input and output of MYSQL is more complicated than what is mentioned above. There are 2 default encodings defined in the MYSQL configuration file my.ini, which are default-character-set in [client] and [mysqld]. The default-character-set is used to set the encoding used by the client connection and the database internally by default. The encoding we specified above is actually the command line parameter character_set_client when the MYSQL client connects to the server, which tells the MYSQL server what encoding the client data received is, instead of using the default encoding.
Based on the previous ones, you also need to add database coding before querying/modifying/adding your data.
2. The page declaration encoding is inconsistent with the encoding of the file itself. This rarely happens because if the encoding is inconsistent, what the artist sees in the browser when creating the page will be garbled. More often than not, it is caused by fixing some minor bugs after release, opening the page in the wrong encoding and then saving it. Or you use some FTP software to directly modify files online, such as CuteFTP. Due to incorrect software encoding configuration, the wrong encoding is converted.
3. When renting a virtual host, if the above three encodings are set correctly, sometimes there are still garbled characters. For example, if the web page is encoded in GB2312, it is always recognized as UTF-8 when opened by browsers such as IE. The HEAD of the web page has already stated that it is GB2312. After manually changing the browser encoding to GB2312, the page displays normally. The reason is that the server Apache sets the global default encoding of the server and adds AddDefaultCharset UTF-8 in httpd.conf. At this time, the server will first send the HTTP header to the browser, and its priority is higher than the encoding declared in the page. Naturally, the browser will recognize it incorrectly. There are two solutions. Administrators should add AddDefaultCharset GB2312 to the configuration file of their own virtual machine to override the global configuration, or configure it in .htaccess in their own directory.
Summary: To solve the Chinese garbled code in PHP, the fastest solution is to make the encoding declared on the page consistent with the internal encoding of the database. If the page number applied for the page is inconsistent with the internal encoding of the database, set the connection encoding, mysql_query ("SET NAMES XXX "); XXX is the connection code. Such as mysql_query('SET NAMES UTF8'); [2]
Finally, Chinese is successfully displayed:
nbsp;html>
<meta>
<title>中文</title>
<h1 id="中文">中文</h1>
<?php echo "Hello World!";
?>
Recommended study: "PHP Video Tutorial"
The above is the detailed content of What to do if dw php web page has Chinese garbled characters?. For more information, please follow other related articles on the PHP Chinese website!
ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PMThe article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and
PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PMThe article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.
PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PMArticle discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.
PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PMThe article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand
PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PMThe article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur
OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PMThe article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.
PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PMThe article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.
PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PMThe article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.







