php中的urlencode和rawurlencode的区别
2个回答
2016-04-28 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
php中urlencode和rawurlencode两个方法在处理字母数字,特殊符号,中文的时候结果都是一样的,唯一的不同是对空格的处理,urlencode处理成“+”,rawurlencode处理成“%20”。
对比结果如下:
<?php
test_encode('http://www.baidu.com?a=search&k=eclipse');
test_encode(':/?= ');
test_encode('中文');
function test_encode($s)
{
echo "<b>urlencode('$s')</b> = [<b>";
var_dump(urlencode($s));
echo "</b>]<br/>";
echo "<b>rawurlencode('$s')</b> = [<b>";
var_dump(rawurlencode($s));
echo "</b>]<br/>";
}
运行结果如下:
urlencode('http://www.baidu.com?a=search&k=eclipse') = [string(53) "http%3A%2F%2Fwww.baidu.com%3Fa%3Dsearch%26k%3Declipse" ]
rawurlencode('http://www.baidu.com?a=search&k=eclipse') = [string(53) "http%3A%2F%2Fwww.baidu.com%3Fa%3Dsearch%26k%3Declipse" ]
urlencode(':/?= ') = [string(19) "%3A%2F%3F%3D+%26%23" ]
rawurlencode(':/?= ') = [string(21) "%3A%2F%3F%3D%20%26%23" ]
urlencode('中文') = [string(18) "%E4%B8%AD%E6%96%87" ]
rawurlencode('中文') = [string(18) "%E4%B8%AD%E6%96%87" ]
对比结果如下:
<?php
test_encode('http://www.baidu.com?a=search&k=eclipse');
test_encode(':/?= ');
test_encode('中文');
function test_encode($s)
{
echo "<b>urlencode('$s')</b> = [<b>";
var_dump(urlencode($s));
echo "</b>]<br/>";
echo "<b>rawurlencode('$s')</b> = [<b>";
var_dump(rawurlencode($s));
echo "</b>]<br/>";
}
运行结果如下:
urlencode('http://www.baidu.com?a=search&k=eclipse') = [string(53) "http%3A%2F%2Fwww.baidu.com%3Fa%3Dsearch%26k%3Declipse" ]
rawurlencode('http://www.baidu.com?a=search&k=eclipse') = [string(53) "http%3A%2F%2Fwww.baidu.com%3Fa%3Dsearch%26k%3Declipse" ]
urlencode(':/?= ') = [string(19) "%3A%2F%3F%3D+%26%23" ]
rawurlencode(':/?= ') = [string(21) "%3A%2F%3F%3D%20%26%23" ]
urlencode('中文') = [string(18) "%E4%B8%AD%E6%96%87" ]
rawurlencode('中文') = [string(18) "%E4%B8%AD%E6%96%87" ]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询