At this time, there are encodeuricomponent, decodeuricomponent, it can completely encode the URL to decode, but encountered such as the search engine to use some of the transcoding, and touch the door, no problem, PHP official out of a solution:
Copy Code code as follows:
decodeURIComponent ((str + '). Replace (/\+/g, '%20 '));
He can perfect the search engine's address to decode, because the search engine is only accustomed to "space" for transcoding. Forget to say also accustomed to the Chinese to transfer code ...
All the above solutions to meet Chinese collapse, yes, I also collapsed, that is, part of the code, but also Chinese. It makes me so sad ...
Check for a long time can, do not say you understand ...
Copy Code code as follows:
<script type= "Text/vbscript" >
Function STR2ASC (STRSTR)
STR2ASC = Hex (ASC (STRSTR))
End Function
Function Asc2str (ASCASC)
ASC2STR = Chr (ASCASC)
End Function
</script>
<script type= "Text/javascript" >
/* Here we start UrlEncode and urldecode<a href= "/?tag=%e5%87%bd%e6%95%b0" target= "_blank" > Functions </a>*/
function UrlEncode (str) {
var ret= "";
var strspecial= "!\" #$%& ' () *+,/:;<=>? []^`{|} ~%";
var tt= "";
for (Var i=0;i<str.length;i++) {
var chr = Str.charat (i);
var c=str2asc (CHR);
tt + + chr+ ":" +c+ "n";
if (parseint ("0x" +c) > 0x7f) {
ret+= "%" +c.slice (0,2) + "%" +c.slice (-2);
}else{
if (chr== "")
ret+= "+";
else if (Strspecial.indexof (CHR)!=-1)
ret+= "%" +c.tostring (16);
Else
RET+=CHR;
}
}
return ret;
}
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+=asc2str (parseint ("0x" +asc+str.substring (i+4,i+6));
i+=5;
}else{
Ret+=asc2str (parseint ("0x" +asc));
i+=2;
}
}else{
ret+= CHR;
}
}
return ret;
}
</script>
What about this? Support for browsers that support VB only ... FF, for example, does not support ...
Why to use VB? Because STR2ASC, asc2str This method is JS can not meet ... Below I simulate two JS method, seemingly not to all Chinese valid.
Copy Code code as follows:
function Str2asc (str) {
Return str.charcodeat (0). toString (16);
}
function Asc2str (str) {
return String.fromCharCode (str);
}