What to do if JavaScript is garbled in Chinese in PHP

coldplay.xixi
Release: 2023-03-04 11:04:01
Original
1422 people have browsed it

Solution to the garbled Chinese characters of JavaScript in PHP: 1. Display the declaration as GB2312 in the PHP file, and transcode the Chinese sent to the server; 2. The codes are all encoded in [UTF-8]. Can.

What to do if JavaScript is garbled in Chinese in PHP

Solution to Chinese garbled javascript in PHP:

One of the solutions is to use PHP The file shows that the declaration is GB2312

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

and the Chinese sent to the server is transcoded.

As follows

$_POST["content"]=iconv("UTF-8","gb2312",$_POST["content"]);
Copy after login

So this can solve the problem of garbled characters

Related learning recommendations:javascript video tutorial

The second solution is to use UTF-8 encoding.

Attached test routine

Client

    ajax post test 
Copy after login

Server

         
Copy after login

Related learning recommendations:php programming(video)

The above is the detailed content of What to do if JavaScript is garbled in Chinese in PHP. 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
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!