Url: add add_url_parameters() method

This commit is contained in:
Benjamin Renard 2023-02-27 19:32:12 +01:00
parent 24e3101dd0
commit c55e29d1fa
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -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<string,string> $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;
}