When using AJAX to interact with the background, we often encode and decode Chinese, and for JS there are two functions: encodeuricomponent for encoding, decodeuricomponent for decoding. For PHP in the background, there are two corresponding encoding and decoding functions: UrlEncode for encoding, UrlDecode for decoding. Now look at the following two pieces of code, first to a PHP code:
$myStr 1 = ' I am Chinese ';
$myStr 2 = UrlEncode ($myStr 1);
echo $myStr 1. ' <br/> ';
Echo $myStr 2. ' <br/> ';
Echo UrlDecode ($myStr 2). ' <br/> ';
The PHP code above will output:
I am a Chinese
%e6%88%91%e6%98%af%e4%b8%ad%e5%9b%bd%e4%ba%ba
I am a Chinese
Then look at the JS code:
var myStr1 = ' I am Chinese ';
var myStr2 = encodeURIComponent (MYSTR1);
document.write (MYSTR1);
document.write (' <br/> ');
document.write (MYSTR2);
document.write (' <br/> ');
document.write (decodeURIComponent (MYSTR2));
The above JS code will output:
I am a Chinese
%e6%88%91%e6%98%af%e4%b8%ad%e5%9b%bd%e4%ba%ba
I am a Chinese
And the output of the PHP code above is the same.