开发者

What's the standard way to generate a url like stuff?

开发者 https://www.devze.com 2022-12-17 18:52 出处:网络
$arr = array(\'key1\'=>\'val1\',\'key2\'=>\'val2\'); $str = \'\'; foreach($arr as $k=>$v) { $str .= \'&\' . $k . \'=\' . urlencode($v);
$arr = array('key1'=>'val1','key2'=>'val2');
$str = '';
foreach($arr as $k=>$v)
{
    $str .= '&' . $k . '=' . urlencode($v);
}
echo substr($str,1);

Or

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

Does the $k need to be urlencoded?


Yes; If you use PHP5 i Guess the http_build_query would be just what you need ;)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消