everyone.
Is it possible to replace a specific GET variable value by using RegEx?
Here is what I have in mind.
I have a URL: https://example.com/category/?var1=value1&page=2&var2=value2
It can have different GET variables, but the one that it always has is "page".
What I want to do is this:
- Set the URL value to a string variable in PHP code - Done.
$current_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; - In that string replace the value of the "page" variable with another value but keep the rest of the URL the same so that I could use them for paging buttons - Struggling
- Take the string variable and echo it in a href tag - Done.
<a href="<?php echo $current_link_next; ?>">Next</a>
The "page" value, of course, is not always 2 - it represents the page number where the user currently is so can be anything from 1 to any other integer.
I'm trying to do it with explodes and joins, but haven't succeeded yet. Maybe there is an easier way to replace values using RegEx?
$_GETfor this?