php displays garbled characters

藏色散人
Release: 2023-02-25 14:24:02
Original
11990 people have browsed it

php displays garbled characters

#What should I do if php displays garbled characters?

Methods to solve the problem of Chinese garbled characters in php

1. The encoding of the php file itself and the encoding of the web page should match

a. If If you want to use gb2312 encoding, then PHP should output the header: header("Content-Type: text/html; charset=gb2312"), and add , the encoding format of all files is ANSI, you can open it with Notepad, save as, select the encoding as ANSI, and overwrite the source file.

b. If you want to use utf-8 encoding, then php should output the header: header("Content-Type: text/html; charset=utf-8"), and add , the encoding format of all files is utf-8. Saving as utf-8 may be a bit troublesome. Generally, utf-8 files will have BOM at the beginning. If you use session, there will be problems. You can use editplus to save. In editplus, go to Tools->Parameter Selection->File-> UTF-8 signature, select Always delete, then save to remove the BOM information.

2. PHP itself is not Unicode. All functions such as substr must be changed to mb_substr (mbstring extension needs to be installed); or iconv can be used to transcode.

3. If your HTML file is garbled, you can add UTF8 encoding (international encoding) in the head tag: UTF-8 is an encoding without a country, that is, independent For any language, any language can be used.

For more PHP related knowledge, please visit PHP Tutorial!

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

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!