Solution to the garbled code after loading js in php: 1. Save the written php file as ANSI encoding; 2. Set the encoding in the header of the php file; 3. Set utf- in the place containing the js file. 8 encoding is enough.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if the js in php is loaded with garbled characters? ?
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 ), I checked the information online and added
1. Put the written php file in When saving, save it as ANSI encoding (web page encoding format).
2. Set in the header of the php file:
<meta http-equiv="Content-Type" content="text/html" charset="gb2312"/>
3. Set in the place containing the js file:
<script language="javascript" src="js/register.js"charset="utf-8"></script>
As long as these three aspects are correct, generally There will be no garbled code problem.
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 js in php is garbled after loading. For more information, please follow other related articles on the PHP Chinese website!