主页 > 以太坊钱包imtoken官网 > URL 中的特殊字符问题
URL 中的特殊字符问题
js编码文本涉及3个函数:escape、encodeURI、encodeURIComponent,对应的3个解码函数:unescape、decodeURI、decodeURIComponent
1、传参时需要使用encodeURIComponent,这样组合的url不会被#等特殊字符截断。
例如:
2. 进行url跳转时可以整体使用encodeURI
例如:location.href=encodeURI("http://cang.baidu.com/do/s?word=Baidu&ct=21");
3、JS在使用数据时可以使用escape
例如:收集历史记录。
4、escape编码0-255以外的unicode值时,输出%u****格式。 其他情况下escape、encodeURI、encodeURIComponent的编码结果是一样的。
用的最多的应该是encodeURIComponent,它将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果需要使用encodeURIComponent给后台传参比特币字符比特币字符,需要后台解码支持utf-8(表单中的编码方式与当前页面的编码方式相同)
escape不编码的字符有69个:*,+,-,.,/,@,_,0-9,az,AZ
encodeURI 不编码 82 个字符:!, #, $, &, ', (,), *, +,,, -, ., /, :, ;, =, ?, @, _, ~, 0- 9 , 至, 至
encodeURIComponent 不对 71 个字符进行编码:!、'、(,)、*、-、.、_、~、0-9、az、AZ
public function urlSafeB64Decode($url) {
return base64_decode(strtr($url, '-_,', '+/='));
}
urlencode、Urldecode函数用于对Urldecode编码后的字符串进行解码并返回。