php中urlencode和urldecode 中文字符的转换

来源:互联网 发布:端口查看 编辑:程序博客网 时间:2024/06/10 02:03
 //GB2312的Encodeecho urlencode("中文-_. ")."\n"; //%D6%D0%CE%C4-_.+      //将中文文字转换成urlencode文字编码echo urldecode("%D6%D0%CE%C4-_. ")."\n"; //中文-_.       //将urlencode文字编码转换成中文文字

一、将文件存为UTF-8文件,直接使用urlencode、rawurlencode即可。

$url = 'http://blog.csdn.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
0 0