This article mainly introduces how to deal with url encoding in js and php. For more information, see
Solution: Use js to encode the Chinese characters in the URL. The Code is as follows: <a href = "" onclick = "window. open ('product _ list. php? P_sort = '+ escape ('php development resource'); "> when you click the link, reference: http: // 127.0.0.1/shop/product_list.php? P_sort = PHP % u5F00 % u53D1 % u8D44 % u6E90 % u7F51 generated this effect. Obviously, using PHP urldecode () or base64_decode () cannot be reversed. Solution: Use PHP to write an anti-decoding function. The Code is as follows: function js_unescape ($ str) {$ ret = ''; $ len = strlen ($ str ); for ($ I = 0; $ I <$ len; $ I ++) {if ($ str [$ I] = '%' & $ str [$ I + 1] = 'U ') {$ val = hexdec (substr ($ str, $ I + 2, 4); if ($ val <0x7f) $ ret. = chr ($ val); else if ($ val <0x800) $ ret. = chr (0xc0 | ($ val> 6 )). chr (0x80 | ($ val & 0x3f); else $ ret. = chr (0xe0 | ($ val> 12 )). chr (0x80 | ($ val> 6) & 0x3f )). chr (0x80 | ($ val & 0x3f); $ I + = 5 ;} Else if ($ str [$ I] = '%') {$ ret. = urldecode (substr ($ str, $ I, 3); $ I + = 2;} else $ ret. = $ str [$ I];} return $ ret;} note that JavaScript code is automatically converted to a UTF-8, so the Code must be converted to get the correct results, otherwise the Chinese garbled. The Code is as follows: print iconv ('utf-8', 'gb2312', js_unescape ($ _ REQUEST ['P _ sort ']); at this point, we have successfully reversed the js escape code. In addition, I found a function using PHP to implement js escape encoding: the code is as follows: function phpescape ($ str) {$ sublen = strlen ($ str); $ retrunString = ""; for ($ I = 0; $ I <$ sublen; $ I ++) {if (ord ($ str [$ I]) >= 127) {$ tmpString = bin2hex (iconv ("gb2312", "ucs-2", substr ($ str, $ I, 2); // $ tmpString = substr ($ tmpString, 2, 2 ). substr ($ tmpString,); this option may be enabled in window $ retrunString. = "% u ". $ tmpString; $ I ++;} else {$ retrunString. = "% ". dechex (ord ($ str [$ I]) ;}return $ retrunString ;}