Skip to content

Instantly share code, notes, and snippets.

@ahoulgrave
Last active March 10, 2016 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahoulgrave/8bc506f17d44fa4186e3 to your computer and use it in GitHub Desktop.
Save ahoulgrave/8bc506f17d44fa4186e3 to your computer and use it in GitHub Desktop.
Function to append a parameter to an url querystring
/**
* @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