This article mainly introduces the JS and PHP URL encoding processing methods, the need for friends can refer to the following
Workaround: Use JS to the URL of the Chinese character escape code. The code looks like this: When you click on the link, the effect is: reference: http://127.0.0.1/shop/product_list.php?p_sort=PHP%u5F00%u53D1%u8D44%u6E90%u7F51 generates such effects, It is obvious that PHP's UrlDecode () or base64_decode () cannot be reversed. Workaround, write an inverse function in PHP: 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; The else if ($str [$i] = = '% ') {$ret. = UrlDecode (substr ($str, $i, 3)), $i + = 2;} else $ret. = $str [$i]; } return $ret;} Note that the JS encoding will automatically be converted into UTF-8, so the encoding must be converted to get the correct results, otherwise it will be garbled in Chinese. The code is as follows: Print iconv (' utf-8 ', ' gb2312 ', Js_unescape ($_request[' p_sort ')); To this we have successfully reversed the JS escape code. In addition I found a PHP implementation of the Escape encoding function: 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, 0,2); You may want to open this entry under window $retrunstring.= "%u". $tmpString; $i + +;} else {$retrunString. = "%". Dechex (Ord ($str [$i]);}} return $retrunString;}
http://www.bkjia.com/PHPjc/737707.html www.bkjia.com true http://www.bkjia.com/PHPjc/737707.html techarticle This article mainly introduces the JS and PHP URL encoding processing methods, the need for friends can refer to the solution: the use of JS to the URL of the Chinese character escape code. The code is as follows: a hr ...