- JS的编码、解码方法里,decodeURI和PHP的urlencode方法不同,无法对PHP的urlencode进行解码。
- function URLdecode(str) {
- var ret = “”;
- for(var i=0;i<str.length;i++) {
- var chr = str.charAt(i);
- if(chr == “+”) {
- ret += ” “;
- }else if(chr==”%”) {
- var asc = str.substring(i+1,i+3);
- if(parseInt(“0x”+asc)>0x7f) {
- ret += decodeURI(“%”+ str.substring(i+1,i+9));
- i += 8;
- }else {
- ret += String.fromCharCode(parseInt(“0x”+asc));
- i += 2;
- }
- }else {
- ret += chr;
- }
- }
- return ret;
- }
- alert(URLdecode(“<?php echo $test_1 ?>”));
转载于:https://my.oschina.net/ming0929/blog/810394