您好,欢迎访问一九零五行业门户网

php中urlencode()函数详解说明

php教程中urlencode()函数详解说明
urlencode:是指针对网页url中的中文字符的一种编码转化方式,最常见的就是baidu、google等搜索引擎中输入中文查询时候,生成经过encode过的网页url。
urlencode的方式一般有两种,一种是传统的基于gb2312的encode(baidu、yisou等使用),另一种是基于utf-8的encode(google、yahoo等使用)。
本工具分别实现两种方式的encode与decode:
中文 -> gb2312的encode -> %d6%d0%ce%c4
中文 -> utf-8的encode -> %e4%b8%ad%e6%96%87
html中的urlencode:
编码为gb2312的html文件中:http://ud03.kinoko.name/中文.rar -> 浏览器自动转换为 -> http://ud03.kinoko.name/%d6%d0%ce%c4.rar
注意:firefox对gb2312的encode的中文url支持不好,因为它默认是utf-8编码发送url的,但是ftp://协议可以,我试过了,我认为这应该算是firefox一个bug。
编码为utf-8的html文件中:http://ud03.kinoko.name/中文.rar -> 浏览器自动转换为 -> http://ud03.kinoko.name/%e4%b8%ad%e6%96%87.rar
php中的urlencode:
除了“-_.”之外的所有非字母数字字符都将被替换成百分号“%”后跟两位十六进制数。
urlencode和rawurlencode的区别:urlencode将空格编码为加号“+”,rawurlencode将空格编码为加号“%20”。
如果要使用utf-8的encode,有两种方法:
一、将文件存为utf-8文件,直接使用urlencode、rawurlencode即可。
二、使用mb_convert_encoding函数:
实例:
javascript中的urlencode:
如:%e4%b8%ad%e6%96%87-_.%20%e4%b8%ad%e6%96%87-_.%20
encodeuri不对下列字符进行编码:“:”、“/”、“;”、“?”、“@”等特殊字符。
如:http://ud03.kinoko.name/%e4%b8%ad%e6%96%87.rarhttp%3a%2f%2fud03.kinoko.name%2f%e4%b8%ad%e6%96%87.rar
本文链接:
收藏随意^^请保留教程地址.
其它类似信息

推荐信息