note 58964 deleted from function.urlencode by peehaa
| From: | peehaa@php.net | Date: | Fri, 06 Jan 2017 15:50:47 +0000 |
| Subject: | note 58964 deleted from function.urlencode by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208695@lists.php.net to get a copy of this message | ||
Note Submitter: roberlamerma at gmail dot com
----
I rewrote inus at flowingcreativity dot net function to generate an encoded url string from the
POST, or GET array. It handles properly POST/GET array vars.
function _HTTPRequestToString($arr_request, $var_name, $separator='&') {
$ret = "";
if (is_array($arr_request)) {
foreach ($arr_request as $key => $value) {
if (is_array($value)) {
if ($var_name) {
$ret .= $this->_HTTPRequestToString($value, "{$var_name}[{$key}]", $separator);
} else {
$ret .= $this->_HTTPRequestToString($value, "{$key}", $separator);
}
} else {
if ($var_name) {
$ret .= "{$var_name}[{$key}]=".urlencode($value)."&";
} else {
$ret .= "{$key}=".urlencode($value)."&";
}
}
}
}
if (!$var_name) {
$ret = substr($ret,0,-1);
}
return $ret;
}