note 38808 added to function.http-build-query
| From: | phpatbrayradotnospamdotcom at rn2 dot php dot net | Date: | Wed, 07 Jan 2004 17:22:05 +0000 |
| Subject: | note 38808 added to function.http-build-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63085@lists.php.net to get a copy of this message | ||
I needed this functionality in 4.2.2. So, here is the function to generate it. This should be
compatible with php > 3.0.7.
Hope this helps.
// This is being added to PHP. So use system function if it exists
if(!function_exists('http_build_query')){
function http_build_query($formdata, $numeric_prefix = ''){
return _http_build_query($formdata,$numeric_prefix);
}
function _http_build_query($formdata, $numeric_prefix = '',$key_prefix=''){
if($numeric_prefix != '' && !is_numeric($numeric_prefix)){
$prefix=$numeric_prefix;
} else {
$prefix = '';
}
if(!is_array($formdata)) return '';
$str='';
foreach($formdata as $key => $val){
if(is_numeric($key))$key=$prefix.$key;
if($str != '') $str.='&';
if($key_prefix != '') {
$mykey = $key_prefix."[$key]";
} else {
$mykey=&$key;
}
if(is_array($val)){
$str.=_http_build_query($val,'',$mykey);
} else {
$str.=$mykey.'='.urlencode($val);
}
}
return $str;
}
}
----
Manual Page -- http://www.php.net/manual/en/function.http-build-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38808
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38808&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38808&report=yes
Search -- http://master.php.net/manage/user-notes.php