-1
$url = localhost/project/index.php?letter=0&position=0&bypass=1

How to change position=0 to position=1?

The new $url value will be:

$url = localhost/project/index.php?letter=0&position=1&bypass=1
Raven
  • 1
  • 1
  • 1
    why u need to change URL? why not to overwrite the just value like `if($_GET['position'] == 0){$_GET['position'] = 1;}`?? you are using str_replace tag but not using it in your code? – devpro Jul 05 '19 at 11:22
  • use string replace – ManiMuthuPandi Jul 05 '19 at 11:23
  • @devpro some headings and forms will be changed if I go to **position=1** from *position=0*. It's not necessary it will have 1 or 2. It can be anything..., for example here I used 1 & 2 – Raven Jul 05 '19 at 11:25
  • 1
    Possible duplicate of [PHP: Change URL parameter](https://stackoverflow.com/questions/47196081/php-change-url-parameter) – MrUpsidown Jul 05 '19 at 11:44

2 Answers2

0

You can use parse-str and parse-url approach with the help of http-build-query,

$url = "localhost/project/index.php?letter=0&position=0&bypass=1";
// fetching query paramters and save it to output variable
parse_str(parse_url($url,PHP_URL_QUERY),$output);
// changing position value
$output["position"] = 1;
// building back query string
$query = http_build_query($output);
// creating final string
echo parse_url($url,PHP_URL_PATH)."?".$query;

Demo
Output:-

localhost/project/index.php?letter=0&position=1&bypass=1
Rahul
  • 18,271
  • 7
  • 41
  • 60
-1

You have to use the str_replace() function to replace a specific text from string.

$url = str_replace('position=0','position=1',$url);
Dolar
  • 423
  • 2
  • 10