Home > Article > Backend Development > php cannot display Chinese
php cannot display Chinese?
php cannot display Chinese because the data encoding is inconsistent.
Encoding of PHP web page
1. The encoding of the php file itself and the encoding of the web page should match
a. If you want to use gb2312 encoding, then PHP needs to output the header:
header("Content-Type: text/html; charset=gb2312")
, add <meta http-equiv="Content- Type" content="text/html; charset=gb2312">
, 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 needs to output the header:
header("Content-Type: text/html; charset=utf-8")
, add <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
to the static page, and 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 save it with editplus. 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.
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of php cannot display Chinese. For more information, please follow other related articles on the PHP Chinese website!