Forum Moderators: coopster
This is a function the php guys should implement internally for performance, but this function does the job fine:
function full_url_encode($params) {
$result = "";
if(is_array($params)) {
foreach($params as $key=>$value) {
if(is_array($value)) {
foreach($value as $vkey=>$vvalue) {
$result .= sprintf('%s[]=%s&', $key, urlencode(stripslashes($vvalue)));
}
}
else {
$result .= sprintf('%s=%s&',$key,urlencode(stripslashes($value)));
}
}
$result = preg_replace('/\&$/','',$result);
}
else {
$result = urlencode(stripslashes($params));
}
return $result;
}
Related to a different topic, another missing php function is something like this.
function array_get($array, $key, $default = null) {
if (! isset ( $array [$key] )) {
return $default;
}
return $array [$key];
}
Thanks for posting those functions. :)
I think that http_build_query [php.net]() will reverse a parse_str as long as you used the optional array variable.