The page: /index.php?page=6&test=1&test2=2
The code below strip’s page=6 off of this so I can add our new page to the url and add the $url_without_page_var back to our link again:
$_SERVER['argv'][0]
// Displays: page=6&test=1&test2=2
And
$url_without_page_var=preg_replace('/page=(\d+)/i','',$_SERVER['argv'][0]);
// Displays: &test=1&test2=2
Ok so that code lets me take the page=6 off of page=6&test=1&test2=2
I can then change the page number and add this all back together.
My problem is often the page in the URL will not always be in the same position, it may not be the 1st or last items
And this is what will happen when, see how the URL is incorrect now;
/page.php?&**test=1&test2=2 **ERROR-HERE-ALSO page=9
The
$_GETvariable provides an array of all the variables set through the URL.$_REQUESTis an array of all theGETandPOSTvariables set. Here’s the fish:Regex is a bit overkill for this problem.
Hope it makes sense. I’ve been writing Python and Javascript for the past few weeks. PHP feels like a step backwards.
EDIT: This code makes me happier. I actually tested it instead of blindly typing and crossing fingers.