Update addURLParameter to allow for a leading ?. re #40

This commit is contained in:
Sébastien Lucas 2013-04-03 14:54:03 +02:00
parent 51a97f8e57
commit f8f20f3d5c

View file

@ -175,14 +175,19 @@ function localize($phrase, $count=-1) {
} }
function addURLParameter($urlParams, $paramName, $paramValue) { function addURLParameter($urlParams, $paramName, $paramValue) {
$start = "";
if (preg_match ("#^\?(.*)#", $urlParams, $matches)) {
$start = "?";
$urlParams = $matches[1];
}
$params = array(); $params = array();
parse_str($urlParams, $params); parse_str($urlParams, $params);
if (empty ($paramValue)) { if (empty ($paramValue) && $paramValue != 0) {
unset ($params[$paramName]); unset ($params[$paramName]);
} else { } else {
$params[$paramName] = $paramValue; $params[$paramName] = $paramValue;
} }
return http_build_query($params); return $start . http_build_query($params);
} }
class Link class Link