1PHP$url = 'http://example.com/whatever/?hello=world';
2shapeSpace_add_var($url, 'goodbye', 'nightclub');
1PHPfunction shapeSpace_add_var($url, $key, $value) {
2
3 $url = preg_replace('/(.*)(?|&)'. $key .'=[^&]+?(&)(.*)/i', '$1$2$4', $url .'&');
4 $url = substr($url, 0, -1);
5
6 if (strpos($url, '?') === false) {
7 return ($url .'?'. $key .'='. $value);
8 } else {
9 return ($url .'&'. $key .'='. $value);
10 }
11}