12 February 2014

urlencode():用于编码URL中的参数部分。 rawurlencode():用于编码URL路径部分。

示例代码:

1
2
3
4
5
6
<?php
$path  = 'test work';
$param = '123 456 789';
$url   = 'http://localhost/'.rawurlencode($path).'.php?id='.urlencode($param);
echo $url."\n";//http://localhost/test%20work.php?id=123+456+789
?>