diff options
Diffstat (limited to 'url.class')
-rw-r--r-- | url.class | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -527,6 +527,40 @@ function encode($str) return strtr(urlencode($str), array("%2C"=>",", "%28"=>"(", "%29"=>")")); } +/** + * Create GET request from params, optionally only using given fields + * @param $params Array to take values from, usually $_GET + * @param $keys Keys to use; default: all + */ +function params($params, $keys = null) +{ + return join("&", it_url::_params($params, $keys)); +} + +function _params($params, $keys = null) +{ + $result = array(); + + if (!isset($keys)) + $keys = array_keys($params); + + foreach ($keys as $key) + { + if (is_array($params[$key])) + { + foreach (it_url::_params($params[$key]) as $value) + { + if (strlen($value)) + $result[] = it::replace('^([^=\[]*)' => $key . '[$1]', $value); + } + } + else if (strlen($params[$key])) + $result[] = urlencode($key) . "=" . it_url::encode($params[$key]); + } + + return $result; +} + } ?> |