Skip to content

Instantly share code, notes, and snippets.

@mikemadisonweb
Last active August 29, 2015 14:23
Show Gist options
  • Save mikemadisonweb/9d763d494a63c9fed832 to your computer and use it in GitHub Desktop.
Save mikemadisonweb/9d763d494a63c9fed832 to your computer and use it in GitHub Desktop.
GET-POST
function add_querystring_var($url, $key, $value) {
$url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
if (strpos($url, '?') === false) {
return ($url . '?' . $key . '=' . $value);
} else {
return ($url . '&' . $key . '=' . $value);
}
}
function remove_querystring_var($url, $key) {
$url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
return ($url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment