开发者

PHP, replace url query var's value

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜