site.com/page1.php?a=1&b=2,how将a = 1替换为a = 3?并获得一个新的网址字符串。
答案 0 :(得分:7)
使用parse_str
将值提取到数组中,更改它们并使用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