Url: add add_url_parameters() method
This commit is contained in:
parent
24e3101dd0
commit
c55e29d1fa
1 changed files with 18 additions and 3 deletions
21
src/Url.php
21
src/Url.php
|
@ -520,18 +520,33 @@ class Url {
|
||||||
* Add parameter in specified URL
|
* Add parameter in specified URL
|
||||||
*
|
*
|
||||||
* @param string &$url The reference of the 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 string $value The parameter value
|
||||||
* @param boolean $encode Set if parameter value must be URL encoded (optional, default: true)
|
* @param boolean $encode Set if parameter value must be URL encoded (optional, default: true)
|
||||||
*
|
*
|
||||||
* @return string The completed URL
|
* @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)
|
if (strpos($url, '?') === false)
|
||||||
$url .= '?';
|
$url .= '?';
|
||||||
else
|
else
|
||||||
$url .= '&';
|
$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;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue