Are you familiar with JS? it helps convert a piece of code into PHP. & Lt; script & gt; var & nbsp; URLEncode & nbsp; {& nbsp; map: & nbsp ;{& nbsp; & nbsp; 0: & nbsp; 0, & nbsp; & is nb familiar with JS, converts a piece of code to PHP.
Script
Var URLEncode = {
Map :{
'0': '0 ',
'1': '1 ',
'2': '2 ',
'3': '3 ',
'4': '4 ',
'5': '5 ',
'6': '6 ',
'7': '7 ',
'8': '8 ',
'9': '9 ',
'10': 'A ',
'11': 'B ',
'12': 'C ',
'13': 'D ',
'14': 'e ',
'15': 'F'
},
ToHex: function (num ){
Var s = [];
While (num> = 16 ){
S. unshift (URLEncode. map [num % 16]);
Num = Math. floor (num/16 );
}
S. unshift (URLEncode. map [num]);
Return '%' + s. join ('');
},
Exec: function (url ){
Var exp =/^ ([a-z] +: \/) ([^/] *) (. *)/;
Var a, B, c, len, arr;
Arr = url. match (exp );
A = arr [1];
B = arr [2];
C = arr [3];
Len = B. length;
For (var I = 0; I <len; I ++ ){
A + = URLEncode. toHex (B. charAt (I). charCodeAt ());
}
Return a + (c. length? C :'/');
}
}
Var teststr = 'http: // baidu.com ';
Alert ('before encryption: '+ teststr );
Alert ('encrypted: '+ URLEncode.exe c (teststr ));
Alert ('decrypted: '+ unescape(URLEncode.exe c (teststr )));
Script
------ Solution --------------------
var URLEncode = {
map: {
'0': '0',
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',