$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
$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
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
You have to use the str_replace() function to replace a specific text from string.
$url = str_replace('position=0','position=1',$url);