PHP - urlencode和rawurlencode的区别
2017-03-24 15:06
357 查看
昨天看UCHome源码的时候,发现有些地方用urlencode,有些地方用rawurlencode。由于对这两个方法的差异不是很清楚,特意写了一段代码来测试。
请将下面的代码保存到一个PHP文件中:
[php]
view plain
copy
<?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/>";
}
上面代码执行结果如下:
[php]
view plain
copy
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" ]
从上面的执行结果可以看出,urlencode和rawurlencode两个方法在处理字母数字,特殊符号,中文的时候结果都是一样的,唯一的不同是对空格的处理,urlencode处理成“+”,rawurlencode处理成“%20”。
请将下面的代码保存到一个PHP文件中:
[php]
view plain
copy
<?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/>";
}
上面代码执行结果如下:
[php]
view plain
copy
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" ]
从上面的执行结果可以看出,urlencode和rawurlencode两个方法在处理字母数字,特殊符号,中文的时候结果都是一样的,唯一的不同是对空格的处理,urlencode处理成“+”,rawurlencode处理成“%20”。
相关文章推荐
- php中urlencode与rawurlencode的区别
- PHP - urlencode和rawurlencode的区别
- PHP - urlencode和rawurlencode的区别
- PHP中urlencode和rawurlencode的区别
- PHP - urlencode和rawurlencode的区别
- PHP urlencode()和rawurlencode()使用和区别
- 浅谈php中urlencode与rawurlencode的区别
- 浅谈php中urlencode与rawurlencode的区别
- PHP - urlencode和rawurlencode的区别
- php中urlencode和rawurlencode的区别,以及对utf的处理
- PHP中rawurlencode和urlencode、JS中encodeURI与encodeURIComponent 的区别
- PHP urlencode()和rawurlencode()的区别
- php中urlencode与rawurlencode的区别有那些呢
- php中urlencode与rawurlencode的区别, parse_url, simplexml_load_string
- PHP中rawurlencode和urlencode、JS中encodeURI与encodeURIComponent 的区别
- PHP - urlencode和rawurlencode的区别
- php中urlencode与rawurlencode的区别
- php urlencode与rawurlencode的区别
- PHP中的urlencode,rawurlencode和JS中的encodeURI,encodeURIComponent
- PHP中htmlentities,htmlspecialchars,urlencode和base64_encode的使用及区别