I am trying to remove the query string from a url, but I need to leave the first key/var intact. So I know what first occurrence of an ampersand is the point from which I want to discard the query string. What would the best way to do this? Below is my code, which currently just keeps appending to the query string.
<a href="<?php echo $_SERVER["REQUEST_URI"] ?>&sortkey=year&sortval=asc">
If i understood your question correctly, you want to strip out everything after 1st occurrence of ampersand. You can use something like this:
The pattern:
Is replaced by first group (
$1), which is anything before first occurrence of&.