1

site.com/page1.php?a=1&b=2,how to replace a=1 to a=3? and get a new url string.

1 Answer 1

7

Use parse_str to extract the values into an array, alter them, and emit with http_build_query:

$query = "a=1&b=2";
parse_str($query, $vals);
$vals['a'] = '3';
$fixed_query = http_build_query($vals);

parse_str docs: http://php.net/manual/en/function.parse-str.php

http_build_query: http://www.php.net/manual/en/function.http-build-query.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.