site.com/page1.php?a=1&b=2,how to replace a=1 to a=3? and get a new url st开发者_如何学运维ring.
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
精彩评论