Home > Article > Backend Development > Ajax+php Chinese garbled solution_PHP tutorial
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
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
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");
}
?>