PHP中的urlencode
来源:互联网 发布:淘宝买家评论怎么写 编辑:程序博客网 时间:2024/06/07 11:33
PHP中的urlencode:
<?php
//GB2312的Encode
echo urlencode("中文-_. ")."\n"; //%D6%D0%CE%C4-_.+
echo urldecode("%D6%D0%CE%C4-_. ")."\n"; //中文-_.
echo rawurlencode("中文-_. ")."\n"; //%D6%D0%CE%C4-_.%20
echo rawurldecode("%D6%D0%CE%C4-_. ")."\n"; //中文-_.
?>
除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数。
urlencode和rawurlencode的区别:
urlencode 将空格则编码为加号(+)
rawurlencode 将空格则编码为加号(%20)
我上个版本的txt文件分割器(在线)代码都是采用urlencode,从来没有发现过这个问题,结果导致今天出了严重的bug,所有带空格的url都无法解析了,导致分割好的文件无法下载。使用rawurlencode()函数,解决了这个问题。
如果要使用utf-8的Encode,有两种方法:
一、将文件存为utf-8文件,直接使用urlencode、rawurlencode即可。
二、使用mb_convert_encoding函数。
<?php
$url = 'http://www.huikaiche.com/中文.rar';
echo urlencode(mb_convert_encoding($url, 'utf-8', 'gb2312'))."\n";
echo rawurlencode(mb_convert_encoding($url, 'utf-8', 'gb2312'))."\n";
//http%3A%2F%2Fwww.huikaiche.com%2F%E4%B8%AD%E6%96%87.rar
?>
应用实例:
function parseurl($url="")
{
$url = rawurlencode(mb_convert_encoding($url, 'gb2312', 'utf-8'));
$a = array("%3A", "%2F", "%40");
$b = array(":", "/", "@");
$url = str_replace($a, $b, $url);
return $url;
}
$url="ftp://yongfu:password@www.huikaiche.com/中文/中文.rar";
echo parseurl($url);
//ftp://yongfu:password@www.huikaiche.com/%D6%D0%CE%C4/%D6%D0%CE%C4.rar
?>
- PHP中的urlencode
- php中的urlencode()、urldecode() 的使用方法
- php中的urlencode()、urldecode() 的使用方法
- php urlencode()
- php urlencode()
- urlencode.php
- php post数据过程中的转义字符与urlencode编码
- php URLEncode()
- PHP urlencode详解
- php urlencode 和 urldecode
- php urlencode和urldecode
- php urlencode()函数详解
- javascript中的urlencode
- Python中的urlencode
- PHP的rawurlencode和urlencode
- js实现php函数urlencode
- PHP urldecode()与urlencode()函数
- php中urldecode()和urlencode()
- 数据库连接的代码
- VMWare 网络连接的三种工作模式(bridged、host-only、NAT)
- 寻址方式的应用
- C++信号量 Semaphore 和 MFC中的 CSemaphore类使用
- WPF下的资源问题
- PHP中的urlencode
- Qt解析xml
- Eclipse PDT安装配置XDebug和subversion(windows系统)
- 事件内核对象 event对象 和MFC中 CEvent类
- Java讲座,第一讲
- kvm 网卡Bridge设置
- linux下 tar解压 gz解压 bz2等各种解压文件使用方法
- 分享的博客地址
- 异常 Exception(Error) (转贴)