I attempted to answer this question (answer deleted, so here is my code).
<?php
function remove_get_param($uri, $name) {
return preg_replace('/(?<=\?|&|;)' . preg_quote($name, '/') . '=[^&;]*/', '', $uri);
}
My initial code was consuming the first param such as ?
when it shouldn't. I tried to do a lookbehind assertion but PHP said...
Warning: preg_replace(): Compilation failed: nothing to repeat at offset 11 on line 4
I'm relatively new with regex assertions, but I assumed that a lookbehind assertion means make sure this pattern precedes, but don't consume it as part of the match.
I looked up the syntax by googling regex cheetsheat and the resulting PNG I downloaded said that the syntax was ?<=
.
What am I doing wrong?
Thanks
Update
Hello again. Here is some example usage that caused the warning above twice...
echo remove_get_param('http://mysite.com?param1=1&param2=2', 'param2') . "\n";
echo remove_get_param('http://mysite.com?param1=1&param2=2', 'param1');
I should also mention I got these errors on codepad.org. Sorry for failing to mention that, I know codepad.org runs in a funky environment.