Home >Backend Development >PHP Problem >What to do if the script in php is garbled

What to do if the script in php is garbled

藏色散人
藏色散人Original
2022-01-19 10:19:081780browse

Solution to the garbled script in php: 1. When saving the written php file, save it as ANSI encoding; 2. Set "charset="gb2312"" in the header of the php file; 3. Set "charset="utf-8"" where the js file is included.

What to do if the script in php is garbled

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

What should I do if the script in php is garbled?

Completely solve the Chinese garbled problem caused by js included in php

Today, when writing the login module of php, the js file was included in the php file for login. Basic standard detection, but when previewing in the browser, garbled characters appeared (there is a setting in the head where the js file is included. , so when previewing in the browser, the garbled characters turned into Chinese, and continued to write down. When writing another file, in order to avoid the same problem, the method adopted was the same as before, but again in the browser preview At that time, the problem of garbled codes appeared again. Now I have considered whether it is a problem with web page encoding. After summarizing, I have come to the following conclusion. In order to prevent garbled codes from appearing in web page encoding:

1. Save the written php file in When, save it as ANSI encoding (web page encoding format).

2. Set in the header of the php file: .

3. Set where the js file is included:

As long as these three aspects are correct, there will generally be no garbled code problems.

My summary just now is due to my lack of experience, so please share your feedback with me and make corrections! !

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if the script in php is garbled. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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