From c55e29d1fa6caef6018dd6e17e511f2d949b6079 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 27 Feb 2023 19:32:12 +0100 Subject: [PATCH] Url: add add_url_parameters() method --- src/Url.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Url.php b/src/Url.php index a739f57..f41aed7 100644 --- a/src/Url.php +++ b/src/Url.php @@ -520,18 +520,33 @@ class Url { * Add parameter in specified URL * * @param string &$url The reference of the URL - * @param string $param The parameter name + * @param string $parameter The parameter name * @param string $value The parameter value * @param boolean $encode Set if parameter value must be URL encoded (optional, default: true) * * @return string The completed URL */ - public static function add_url_parameter(&$url, $param, $value, $encode=true) { + public static function add_url_parameter(&$url, $parameter, $value, $encode=true) { if (strpos($url, '?') === false) $url .= '?'; else $url .= '&'; - $url .= "$param=".($encode?urlencode($value):$value); + $url .= "$parameter=".($encode?urlencode($value):$value); + return $url; + } + + /** + * Add parameters in specified URL + * + * @param string &$url The reference of the URL + * @param array $parameters The parameters as an associative array + * @param boolean $encode Set if parameters values must be URL encoded (optional, default: true) + * + * @return string The completed URL + */ + public static function add_url_parameters(&$url, $parameters, $encode=true) { + foreach($parameters as $parameter => $value) + self :: add_url_parameter($url, $parameter, $value, $encode); return $url; }