生成类似网址的标准方法是什么?

时间:2010-01-24 13:06:37

标签: php url

$arr = array('key1'=>'val1','key2'=>'val2');
$str = '';
foreach($arr as $k=>$v)
{
    $str .= '&' . $k . '=' . urlencode($v);
}
echo substr($str,1);

或者

$arr = array('key1'=>'val1','key2'=>'val2');
$str = '';
foreach($arr as $k=>$v)
{
    $str .= '&' . urlencode($k) . '=' . urlencode($v);
}
echo substr($str,1);

$k是否需要进行urlencoded?

1 个答案:

答案 0 :(得分:4)

是; 如果您使用PHP5,我猜猜http_build_query就是您所需要的;)

http://nl2.php.net/manual/en/function.http-build-query.php