Home > Backend Development > PHP Problem > php is garbled when opened

php is garbled when opened

Release: 2023-02-28 06:12:02
Original
3193 people have browsed it

php is garbled when opened

1. Check the problem of converting the HTML page to UTF-8 encoding

1. Add a line after the head and before the title:

<meta http-equiv=&#39;Content-Type&#39; content=&#39;text/html; charset=utf-8&#39; />
Copy after login

The order cannot be wrong , must be after head and before title.

2.html file encoding problem:

Click the menu of the editor: "File"->"Save As", you can see the encoding of the current file, make sure the file encoding is: UTF -8,

If it is ANSI, you need to change the encoding to: UTF-8.

3. HTML file header BOM problem:

When converting a file from other encodings to UTF-8 encoding, sometimes a BOM tag is added at the beginning of the file,

A BOM tag may cause the browser to display garbled characters when displaying Chinese characters.

Methods to delete this BOM tag:

1. You can open the file with Dreamweaver and resave it to remove the BOM tag!

2. You can open the file with EditPlus, and in the menu "Preferences"->"File"->"UTF-8 Signature", set it to: "Always delete signature", and then save the file , that is, the BOM label can be removed!

3. WEB server UTF-8 encoding problem:

If you follow the steps listed above and still have Chinese garbled problems, please check the encoding of the WEB server you are using. Question

If you are using Apache, please set the charset in the configuration file to: utf-8 (only the methods are listed here, please refer to the apache configuration file for the specific format)

If you are using Nginx, please set charset in nginx.conf to utf-8.

Specifically find "charset gb2312;" or a similar statement and change it to: "charset utf-8;" .

2. PHP page conversion to UTF-8 encoding problem

1. Add one at the beginning of the code:

header("Content-Type: text/html;charset=utf-8");
Copy after login

2. PHP file encoding problem:

Click the menu of the editor: "File"->"Save As", you can see the encoding of the current file, make sure the file encoding is: UTF-8,

If it is ANSI, you need to Encoding changed to: UTF-8.

3. Problems with using UTF-8 encoding for MYSQL database

1. Use phpmyadmin to create databases and data tables

When creating a database, please set "Organization" to : "utf8_general_ci"

Or execute the statement:

CREATE DATABASE `dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Copy after login

When creating a data table: If this field stores Chinese, you need to set "Organization" to: "utf8_general_ci",

If the field stores English or numbers, the default is fine.

Recommended: php server

The above is the detailed content of php is garbled when opened. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template