Home  >  Article  >  php教程  >  js/php的encodeURI

js/php的encodeURI

WBOY
WBOYOriginal
2016-06-13 10:43:011163browse

encodeURI() 函数可把字符串作为 URI 进行编码,字符将被十六进制的转义序列进行替换。
decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码。

js的encodeURI()后的字符一般为utf-8编码,如果服务器端编码为不同编码,则需要iconv转换。
$a = urlencode(iconv("gb2312", "UTF-8", "电影")); //等同于javascript encodeURI("电影");
echo $a;
$b = iconv("utf-8","gb2312",urldecode("%E7%94%B5%E5%BD%B1")); //等同于javascript decodeURI("%E7%94%B5%E5%BD%B1");
echo $b;
?> 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn