Last active
March 10, 2016 00:33
-
-
Save ahoulgrave/8bc506f17d44fa4186e3 to your computer and use it in GitHub Desktop.
Function to append a parameter to an url querystring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param $value | |
* @param string $param | |
* @return string | |
*/ | |
public function appendParam($param, $value) | |
{ | |
$url = $this->request->getUri(); | |
$queryString = parse_url($url, PHP_URL_QUERY); | |
$params = []; | |
parse_str($queryString, $params); | |
$url = preg_replace('/\?.*/', '', $url); | |
$params[$param] = $value; | |
return $url . '?' . http_build_query($params); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment