Ajax+php Chinese garbled solution_PHP tutorial

WBOY
Release: 2016-07-20 11:17:53
Original
870 people have browsed it

Since XMLHTTP uses Unicode encoding to upload data, and general pages use gb2312, this causes garbled characters when displaying the page. When getting the page, XMLHttp returns UTF-8 encoding, which causes garbled display.
One of the solutions is to display the declaration as GB2312

in the PHP file

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

And transcode the Chinese sent to the server.
As follows
$_POST["content"]=iconv("UTF-8","gb2312",$_POST["content"]);
Therefore, this can solve the problem of garbled characters

Method 2 uses UTF-8 encoding. Not much to say here

Attached test routine
Client





ajax post test








Server side
header("Content-Type:text/html;charset=GB2312");
if($_POST['content'])
{
$_POST["content"]=iconv("UTF-8","gb2312",$_POST["content"]);
print("The content is".$_POST['content']);
}
else
{
print("No content sent");
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371911.htmlTechArticleSince XMLHTTP uses Unicode encoding to upload data, and general pages use gb2312, this causes the problem when displaying the page. Generate gibberish. When getting the page, XMLHttp returns utf-8...
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!