Last active
August 29, 2015 14:23
-
-
Save mikemadisonweb/9d763d494a63c9fed832 to your computer and use it in GitHub Desktop.
GET-POST
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
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