urlencode在编码空格“ ”时会转义成+号,而rawurlencode在编码空格“ ”时会转义成"% 20"
如果要使用UTF-8的Encode,有两种方法:
一、将文件存为UTF-8文件,直接使用urlencode、rawurlencode即可。
二、使用mb_convert_encoding函数:
<?php $url = 'http://s.jb51.net/中文.rar'; echo urlencode(mb_convert_encoding($url, 'utf-8', 'gb2312'))."\n"; echo rawurlencode(mb_convert_encoding($url, 'utf-8', 'gb2312'))."\n"; //http%3A%2F%2Fs.jb51.net%2F%E4%B8%AD%E6%96%87.rar ?>